This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
preprocessor concatenation issue ...
- From: Mark Nicholson <mnichols at cosinecom dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Wed, 3 Dec 2003 09:07:29 -0800 (PST)
- Subject: preprocessor concatenation issue ...
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