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

Re: gcc 3.0.2 preprocessor token stringization fails


Hi David,

David Thompson wrote:-

> 1) This source code shows a preprocessor failure for gcc-3.0.1
> and gcc-3.0.2 but works correctly in gcc-2.95.3.  Although I am
> using a sun->linux cross compiler, I notice the same failure on
> a native linux gcc-3.0.2 compiler as well.
> 
>   --begin-source: f.c--
>   #define CONCAT2(x,y)        x##y
>   #define CONCAT3(x,y,z)      x##y##z
> 
>   #define QUOTE(macro)        #macro
>   #define QUOTE_MACRO(macro)  QUOTE(macro)
> 
>   #define DEFINE_DEBUGGER(defaultLevel, msgPrefix) \
>      _DEFINE_DEBUGGER(DEBUG_MODULE_NAME, defaultLevel, msgPrefix)
> 
>   #define _DEFINE_DEBUGGER(name, defaultLevel, msgPrefix) \
>     static char *CONCAT3(p,name,MsgPrefix) = \
>     CONCAT3("<",QUOTE_MACRO(name),"> ");

Note that here you are invoking CONCAT3 with 3 tokens, two of which
are '<' and '>'.  As GCC complains, these do not paste with
QUOTE_MACRO at the LHS, and ')' at the right hand side.  Remember, the
## operator takes the two tokens on either side of it, after argument
replacement without expansion, and tries to form a single token by
combining the spellings of the two tokens.  CPP is trying to say that
"<QUOTE_MACRO" and ")>" are not two valid tokens, which is correct.

The preprocessor in 3.x is stricter than earlier ones in quite a
few ways, and this is one of them.

What are you trying to do?  I can't even figure out how the result of
your macros can be valid C code, so I can't suggest an alternative.

Neil.


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