#include <stdio.h>
#define ONE 1
#define TWO 2
#define OOPS 42
#define DEF_FOO(x) void foo_##x(void){ printf(#x" %d\n",x);}
DEF_FOO(ONE);
DEF_FOO(TWO);
DEF_FOO(OOPS);
int main()
{
foo_ONE();
foo_TWO();
foo_OOPS();
return 0;
}
gives :
ONE 1
TWO 2
OOPS 42
I would like this:
#include <stdio.h>
#define ONE 1
#define TWO 2
#define OOPS 42
#define DEF_BAR(x) void bar_??x??(void){ printf(#x" %d\n",x);}
DEF_BAR(ONE);
DEF_BAR(TWO);
DEF_BAR(OOPS);
int main()
{
bar_1();
bar_2();
bar_42();
return 0;
}
gives :
ONE 1
TWO 2
OOPS 42
or (its does not matter)
1 1
2 2
42 42
Could I use the value of a token? In theory, preprocessor should know its value, does it?