It seems that what you want to do can be achieved like this, without running into any problems:
#ifdef DEBUG
# define DO(WHAT) MyObj->WHAT()
#else
# define DO(WHAT) while(false)
#endif
Btw, better use the NDEBUG
macro, unless you have a more specific reason not to. NDEBUG
is more widely used as a macro that means no-debugging. For example the standard assert macro can be disabled by defining NDEBUG
. Your code would become:
#ifndef NDEBUG
# define DO(WHAT) MyObj->WHAT()
#else
# define DO(WHAT) while(false)
#endif