Possible Duplicate:
C, Macro defining Macro
Does anyone know how to pull off something like this...
I have alot of repetitive macros as : -
#define MYMACRO1(x) Do1(x)
#define MYMACRO2(x,y) Do2(x, y)
#define MYNEXTMACRO1(x) Do1(x)
#define MYNEXTMACRO2(x,y) Do2(x, y)
The code above works fine, but I want to write a macro that creates macros (a meta macro).
For example: -
#define MYMETAMACRO(name) \
#define #name1(x) Do1(x) \
#define #name2(x,y) Do2(x, y) \
Such that I can do : -
MYMETAMACRO(MYMACRO);
MYMETAMACRO(MYNEXTMACRO);
and then : -
MYMACRO1(2);
MYMACRO2(2,3);
MYNEXTMACRO1(4);
MYNEXTMACRO2(4, 5);
The preprocessor bombs out at the #define as it thinks it is a missing parameter of the macro.