gcc 3.0.2 preprocessor token stringization fails
Neil Booth
neil@daikokuya.demon.co.uk
Mon Oct 29 13:26:00 GMT 2001
David Thompson wrote:-
> Hi,
>
> 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),"> ");
Ah, I see. Please ignore my previous message, I misread this line.
You cannot paste two string literals and get a string literal.
Instead, change the above line to
#define _DEFINE_DEBUGGER(name, defaultLevel, msgPrefix) \
static char *CONCAT3(p,name,MsgPrefix) = \
"<" QUOTE_MACRO(name) "> ";
You don't need the CONCAT3 thing at all - adjacent string literals are
concatenated automatically by the compiler in a different translation
phase.
Neil.
More information about the Gcc-bugs
mailing list