Hi,
Need some help regarding the macro usage.
I've a case where the parameter to be passed to the macro function is not known till the point it is called.
example: (continuing the example quoted below)
- number "12" passed to the " DEFINE_FUNC( n )" macro is determined at the time of execution.
I cannot pass a string/int var from the macro
(i.e. i cannot use
int num = 12;
DEFINE_NUM(num);
)
Can you please help me and share any solution for such situation?
Thanks in advance!
Aditya
Actually, it is possible. You need to use token concatenation.
#define DEFINE_FUNC( n ) void func_ ## n()
You would use it in the normal way:DEFINE_FUNC( 12 );
The preprocessor would turn that into:void func_12();
While I can't imagine why you want to do this, there are, in fact, legitimate reasons to do token concatenation (which goes a long way into explaining why the preprocessor can do it at all).Hope this helps.