You are here

preprocessor metaprogramming (not directly an MRPT issue)

Hello, In my application, I'm trying to do something like this :
#define ID 42
#define ROOT(pref,post) pref## ID ##post
#define POSTFIX(post) ID##post
#define PRETFIX(post) ID##post
...

the expected result is for instance:
void ROOT(begin,end)(int x); -> void begin42end(int x);
but the obtain result is (at best):
void beginIDend(int x);

I suspect that the preprocessor does not function in a recursive way but is there a way to obtain the expected behaviour (to generate a family of symbols, parametrized by some macro) ?

Thanks
A.
Forums: 
jlblanco's picture

Arhopala's picture

Hello,

Thanks for your answer but it does not the job.
Indeed my aim is to use a macro inside another macro definition in order to avoid an error-prone repetition of argument passing.
With my example, I want to use my macro lije that:
void ROOT(begin,end)(int x); -> void begin42end(int x);
Not like that:
void ROOT(begin,ID,end)(int x);

I think that using a macro inside a macro def is not supported by the preprocessor but I was wondering if there was another way around.
Saying it another way, I'm trying to do some argument binding at the preprocessor level.

By
A.