preprocessor concatenation issue ...
Mark Nicholson
mnichols@cosinecom.com
Wed Dec 3 17:07:00 GMT 2003
Hi,
I'm trying to migrate from gcc 2.95.2 to gcc 3.3.2 and I've run
into an odd incompatibility. Here is the test code:
typedef struct
{
struct
{
unsigned long allocs;
unsigned long fails;
unsigned long frees;
} sleeplocks;
struct
{
unsigned long allocs;
unsigned long fails;
unsigned long frees;
} rwsleeplocks;
struct
{
unsigned long allocs;
unsigned long fails;
unsigned long frees;
} conditions;
struct
{
unsigned long allocs;
unsigned long fails;
unsigned long frees;
} events;
} lockstats_t;
lockstats_t lockstats;
#define LOCKSTATS_ALLOCS_INC(_locktype) \
lockstats. ##_locktype##.allocs++
#define LOCKSTATS_FAILS_INC(_locktype) \
lockstats.##_locktype##.fails++
#define LOCKSTATS_FREES_INC(_locktype) \
lockstats.##_locktype##.frees++
int main( void )
{
LOCKSTATS_FREES_INC(sleeplocks);
/*
* desire to get:
*
* lockstats.sleeplocks.frees++;
*/
return( 0 );
}
I expect to get a main routine with the line:
lockstats.sleeplocks.frees++;
in place of the macro.
When I compile this with GCC 2.95.2, it compiles fine (and works).
When I use GCC 3.3.2, I get these errors:
tcsh-102: gcc -Wall -o go substitution.c
substitution.c:42:39: pasting "." and "sleeplocks" does not give a valid
preprocessing token
substitution.c:42:39: pasting "sleeplocks" and "." does not give a valid
preprocessing token
tcsh-103:
Any ideas if this is actually a bug? Can anyone suggest a
workaround?
By the way, when I recompile it with --save-temps, the code it
spits out is correct (trimmed for brevity):
lockstats_t lockstats;
# 43 "substitution.c"
int main( void )
{
lockstats.sleeplocks.frees++;
return( 0 );
}
Thanks in advance for any wisdom and help!
Cheers!
Mark Nicholson
More information about the Gcc-help
mailing list