#define real function name to __noop in Visual C++ 2013

323 views Asked by At

I can do this in Visual C++ 2008 with Release (NDEBUG) setting:

debug.h

#ifdef _DEBUG

void debug_printf(const char* format, ...);

#else

#define debug_printf(format, v)     __noop

#endif

debug.cpp

#include "stdafx.h"  //#include "debug.h" is inside it

void debug_printf(const char* format, ...) {
    //so much work here
}

but not anymore in Visual C++ 2013, I will get compile error in debug.cpp file. It seems I have to change the defining strategy in debug.h. But I wonder is there compiler setting to reenable again the old way?

1

There are 1 answers

2
Some programmer dude On BEST ANSWER

Use a macro in the first case too, and let it call the actual function (which is named something different from the macro).

And in the second case, just have an empty macro body.

Use variadic macros.


Something like

#ifdef _DEBUG
# define debug_printf(fmt, ...) real_debug_printf(fmt, __VA_ARGS__)
#else
# define debug_printf(fmt, ...)
#endif

When _DEBUG is not defined, then the macro debug_printf is replaced by nothing (or rather, an empty line).