I want to use a noop macro in C (similar to msvc's __noop) that still evaluates its arguments.
example:
#ifdef _DEBUG
#define printf_debug(...) printf(__VA_ARGS__)
#else
#define printf_debug(...) NOOP(__VA_ARGS__)
#endif
int main()
{
int i = 0;
printf_debug("i: %i\n", i++);
return i;//should return 1 when in release mode
}
The simplest thing you can do is this:
#ifdef _DEBUG
#define printf_debug(...) printf(__VA_ARGS__)
#else
#define printf_debug(...) (__VA_ARGS__)
#endif
Although it would generate warning for unused values in a comma expression.
You could also add a noop function:
#ifdef _DEBUG
#define printf_debug(...) printf(__VA_ARGS__)
#else
int printf_noop(const char *p, ...) { (void )p; return 0; }
#define printf_debug(...) printf_noop(__VA_ARGS__)
#endif
This avoids the warnings but still generates a function call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With