#define in a macro definition

Brian Dessent brian@dessent.net
Sun Dec 18 05:58:00 GMT 2005


"Samuel J. Guido" wrote:

> Is it possible with GCC to define an object-like macro within a
> function-like macro, i.e. this is what I am trying to do...
> 
> #define MyMacro(a) \
>     #define a##Type 55

As far as I can tell ISO C99 forbids this, in §6.10.3.2.1 which says:

"Each # preprocessing token in the replacement list for a function-like
macro shall be followed by a parameter as the next preprocessing token
in the replacement list."

So "#define" in the replacement list would be illegal unless 'define'
was a parameter, in which case it would stringify it.

I don't think what you're trying to do is possible in general with gcc,
but I could be wrong.  Maybe if you explain in more detail why you would
need such a thing, someone would be able to offer an alternative.

Brian



More information about the Gcc-help mailing list