I have following preprocessor (code) block in my project before each function definition to unclutter the logging Macro.
#ifdef FC_NAME #undef FC_NAME #endif #define FC_NAME "myFunctionName"
But this itself looks kind of cluttered.
So, I am looking at replacing this with something that looks simpler and tried this
#define REDEF_FC_NAME(funcName) #ifdef FC_NAME \ \ #undef FC_NAME \ \ #endif \ \ #define FC_NAME funcName \
But this gives error saying macro def within a macro. So, is there a way of achieving the same effect?
The short answer is: you can't do that with macros.
In C++, every function has a predefined
GCC offers this as an extension to C, as I'm sure do many other compilers. On Windows, there appears to be the
__FUNCTION__ macro (see http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.71).aspx).
__func__is actually a function-local variable, not a macro - James McNellis 2012-04-04 00:03