This is the mail archive of the gcc-help@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]

Re: #define in a macro definition


Brian Dessent wrote:

"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



I was trying to do exactly this type of thing just last night! My reason is I've got
a bunch of code that reads:
#ifdef FOO
debug("FOO\n");
#endif
It's printing to a debug file to help track down what options were defined. This is
several hundred lines of code, and it's a bit ugly. It would be nice to be able to write "PRINT_MACRO(FOO)" and have it expand to the 3 lines above.



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