I need a macro to pass the __FILE__ and __LINE__ to a function which has default arguments. This has opened up a can of worms, since default args with macros are either not possible or very messy, and I need to support both GCC and MSVC if possible:
class Class
{
#ifdef _DEBUG
int Function(int a, int b = 10, int c = 20) { return a + b + c; }
#else
int DebugFunction(const char* filename, int lineNo, int a, int b = 10, int c = 20)
{
printf("%s (%i) a:%i b:%i c:%i\n", filename, lineNo, a, b, c);
return a + b + c;
}
//Not possible
#define Function( DebugFunction(__FILE__, __LINE__
#endif
}
I’ve tried \escaping the ( to no avail. The codebase is huge, so fixing up the missing default args or creating multiple macros isn’t a popular option.
Any solutions?
You can make a variadic macro:
Since you cannot “overload” macros, this might be your best bet.