This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Parametrized macro names


I'm writing some code which would benefit greatly from the feature I'm
going to describe, and I suspect this feature could come handy to many
others as well, when playing with the preprocessor.

Basically, what I'd like the preprocessor to do is to allow this kind of
macro:

    #define macro ## param1 ## param2 ## ... ## paramN macrobody

param1-N are macros themselves, and the above line defines a macro whose
name is composed of all the other macros' contents, making it parametrized
at all effects.

So, say I have the above #define in an include file, I could do this:

    #define param1 ...
    #define param2 ...
    ...
    #define paramN ...

    #include "macro.h"

And automatically get a new macro named after the parameter's contents.

Right now the preprocessor bails out on the parametrized definition,
because it says that '##' is not allowed at the beginning of a macro body,
so there's no possibility that the above line is ambiguous, and the
preprocessor could simply accept it and build the macro name accordingly.

I suspect it wouldn't be a too hard thing to implement either.

Regards,
Fabio Alemagna




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]