I have similar macros defined with just difference in them is number. e.g
#define Function_01_Call(param) (FunctionName((int)01, param))
#define Function_02_Call(param) (FunctionName((int)02, param))
#define Function_03_Call(param) (FunctionName((int)03, param))
#define Function_04_Call(param) (FunctionName((int)04, param))
I want to call function FunctionName using macros Function_XX_Call. How can I use one string for macro with change in its numbers? I tried with
#define FUNCTION_CALL(num) Function_num_Call
int main()
{
char num;
for(num = "01"; num<="04"; num++)
{
FUNCTION_CALL(num); //HOW TO PASS param HERE?
}
}
but how can I change the num dynamically during call as Variables cannot be used in macro. Also how to pass the param during call? Is there any way to use function pointers?
The best is to create callers and a lookup table. So completely ignore the whole processor stuff anything there is and move to runtime.
Preprocessor is static, it can't be changed after compilation. If you want anything to depend on something on runtime, you have to write it in runtime, not in preprocessor.
The function list and array definition could be "shortened" with FOREACH macros, like
P99_SEQ
orBOOST_PP_SEQ_FOR_EACH
or similar.