views:

154

answers:

2

Since LLVM/cLang is especially well designed.

This seems like a great opportunity to augment the C/C++ macro/preprocessor system.

Does anyone know of

  1. additional macro/preprocessor abilities added by Clang or
  2. side projects to make the macro system more powerful (like turing complete)

Thakns!

Note: I am asking about macros. Not C++ templates. Readers: pleaser downvote any answers referring to templates. I want this thread to be macro/preprocessor specific.

+1  A: 

LLVM/clang is especially well designed. The clang preprocessor is especially nice: It keeps track of macro expansions, etc. I suspect the reason that it has not been extended is that 1. An extended preprocessor is non-standard, and 2. No one has done it. Feel free to extend it. As they say on the LLVM IRC: "Patches are welcome", although I suspect that very non-standard preprocessor extensions may not be.

For an example of a preprocessor taken to the ultimate extreme, take a look at PL/1. ;-)

Richard Pennington
A: 

Why don't you just use M4 as a pre-preprocessor?

Ira Baxter
This sounds interesting, but googling around I can't find how to tell clang to use m4 as a preprocessor how do I do this? In particular, suppose I have one .hpp that includes anotehr .hpp file; how do I tell m4 to preprocess the included file too?
anon
What you'd have to do is to use a script to M4-preprocess all the files (including the headers) first, before you fed them to the actual C++ compiler. The good news is you don't have invent a powerful macro system, as M4 already is Turing-capable. If you insist that the macros be defined *inside* the .hpp files, then you could define the M4 macros inside C++ comments, do a pre-scan of the code to extract and collect the M4 macros, and then do the M4 application.
Ira Baxter