We have an existing function implementation in our C++ code:
void Function(int param)
{
printf("In Function\n");
}
int main()
{
Function(10);
return 0;
}
I wish to change it to call another function (by help of a macro declaration) which would accept additional params like FILE and LINE (for debugging purpose) and then call the actual function:
#define Function(param) Function_debug(param, __FILE__, __FUNCTION__, __LINE__) \
{\
printf("In Function_debug [%s] [%s] [%d]\n", file, func, line); \
Function(param);\
}
But the below code:
#include <stdio.h>
#define Function(param) Function_debug(param, __FILE__, __FUNCTION__, __LINE__) \
{\
printf("In Function_debug [%s] [%s] [%d]\n", file, func, line); \
Function(param);\
}
void Function(int param)
{
printf("In Function\n");
}
int main()
{
Function(10);
return 0;
}
Translates TO:
void Function_debug(int param, "temp.cpp", __FUNCTION__, 9) { printf("In Function_debug [%s] [%s] [%d]\n", file, func, line); Function(int param);}
{
printf("In Function\n");
}
int main()
{
Function_debug(10, "temp.cpp", __FUNCTION__, 16) { printf("In Function_debug [%s] [%s] [%d]\n", file, func, line); Function(10);};
return 0;
}
which gives compilation errors.
Please direct me how to achieve the objective?
Normally you’d do something like this: