My program used many #ifdef _DEBUG_ ... #endif
blocks, to nullify the debugging functions for the release build.
However, it clogs the codes, and makes the codes unpleasant to read.
Is there any better way?
One way I can think of is to nullify it by define the function to empty, such as:
#ifdef _DEBUG_
void foo(int bar)
{
do_somthing();
}
#else
#define foo(a) do {; } while(0)
#endif
So that we have only one #ifdef _DEBUG_ ... #endif
. All the places where foo()
is called, we don't have to add #ifdef _DEBUG_ ... #endif
.
However, there are exceptions:
- When a debug function has a return value, the above strategy will not work. e.g. the codes calling the function may be in this pattern:
bar = foo();
- When a debug function is in the form of a member function of a class, again, the above said strategy will not work.
Any idea?