concatenating in a macro
From: Gergely Buday (gergoe_at_math.bme.hu)
Date: 09/27/04
- Next message: Arthur J. O'Dwyer: "Re: Why is C still being used instead of C++"
- Previous message: Phlip: "Re: execute a new programm without beeing blocked"
- Next in thread: Arthur J. O'Dwyer: "Re: concatenating in a macro"
- Reply: Arthur J. O'Dwyer: "Re: concatenating in a macro"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Sep 2004 12:34:47 -0700
Hi folks,
c++ faq lite writes:
However you need a double layer of indirection when you use ##.
Basically you need to create a special macro for "token pasting" such
as:
#define name2(a,b) name2_hidden(a,b)
#define name2_hidden(a,b) a ## b
Trust me on this --- you really need to do this! (And please nobody
write me saying it sometimes works without the second layer of
indirection. Try concatenating a symbol with __LINE__ and see what
happens then.)
---
Now my code is
#include <stdio.h>
#define MYMACRO(a,b) \
a ## b
int main(int argc, char** argv)
{
int MYMACRO(tmp, __LINE__) = 1;
printf("%d\n", MYMACRO(tmp, __LINE__));
return 0;
}
and it compiles (with g++) and runs smoothly. What does the faq author
talk about?
Thanks in advance
- Gergely
- Next message: Arthur J. O'Dwyer: "Re: Why is C still being used instead of C++"
- Previous message: Phlip: "Re: execute a new programm without beeing blocked"
- Next in thread: Arthur J. O'Dwyer: "Re: concatenating in a macro"
- Reply: Arthur J. O'Dwyer: "Re: concatenating in a macro"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|