I saw different solutions and workarounds of overloading macros. But I seem to have difficulties on this one.
I have a PRINT_DEBUG
macro that prints to the visual studio debugger:
#define DEBUG_PRINT(message, ...) _RPTN(0, message "\n", __VA_ARGS__)
Now say i want to overload it like so:
#define DEBUG_PRINT(message) _RPT0(0, message "\n")
#define DEBUG_PRINT(message, ...) _RPTN(0, message "\n", __VA_ARGS__)
This of course won't work, as it would pick up the first macro.
So I checked other topics and found this solution and here is what I came up with:
#define PRINT_DEBUG(...) _DEBUG_PRINT_SELECT(__VA_ARGS__, _DEBUG_PRINT2, _DEBUG_PRINT1, ...) (__VA_ARGS__)
#define _DEBUG_PRINT_SELECT(_1, _2, NAME, ...) NAME
#define _DEBUG_PRINT1(message) _RPT0(0, message "\n")
#define _DEBUG_PRINT2(message, ...) _RPTN(0, message "\n", __VA_ARGS__)
I'm trying to use it like so:
PRINT_DEBUG("My message");
PRINT_DEBUG("My message %s", someString);
PRINT_DEBUG("My message %s %d", someString, someValue);
Do I really have to hard code each one depending on the amount of arguments I have? or is there any creative way of doing this?
The only work around I found, is to just have a single:
#define PRINT_DEBUG(message, ...) _RPTN(0, message "\n", __VA_ARGS__);
And say I want to print just a message, I have to pass a second parameter in mvsc compilers:
PRINT_DEBUG("My message", NULL);
Any help would be much appreciated! Thanks in advance!