* preprocessor concatenation issue ...
@ 2003-12-03 17:07 Mark Nicholson
0 siblings, 0 replies; 3+ messages in thread
From: Mark Nicholson @ 2003-12-03 17:07 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: preprocessor concatenation issue ...
@ 2003-12-03 18:52 Mark Nicholson
0 siblings, 0 replies; 3+ messages in thread
From: Mark Nicholson @ 2003-12-03 18:52 UTC (permalink / raw)
To: eljay, gcc-help
Eljay,
Thank you! I removed the '##' altogether and it works in both
compilers.
I appreciate the sanity check!
Cheers!
Mark
----------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: preprocessor concatenation issue ...
@ 2003-12-03 18:33 Eljay Love-Jensen
0 siblings, 0 replies; 3+ messages in thread
From: Eljay Love-Jensen @ 2003-12-03 18:33 UTC (permalink / raw)
To: Mark Nicholson, gcc-help
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-12-03 18:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-03 17:07 preprocessor concatenation issue Mark Nicholson
2003-12-03 18:33 Eljay Love-Jensen
2003-12-03 18:52 Mark Nicholson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).