Re: preprocessor concatenation issue ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mark,

Your macros are illegal.

You need to use the preprocessor concatentation operator (##) to make a token.  The dot (.) that is being concatenated against does not form a valid token.

You don't need the concatation operator (##) in them.  If you remove them, then the macros should work correctly.

HTH,
--Eljay


At 09:07 AM 12/3/2003 -0800, Mark Nicholson wrote:
>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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux