A hypothetical question: Is it possible to have a C++ program, which includes preprocessor directives, entirely on one line?
Such a line would look like this:
A few years late - but here is a pattern I use every day:
#ifdef _DEBUG
#define DEBUGTRACE(debuglevel, code) \
if ( traceLevelActive(debuglevel) ) \
{code}
#else
#define DEBUGTRACE(debuglevel, code)
#endif
Usage:
DEBUGTRACE(DEBUG_LEVEL2, printf("you are in debug mode"); );
or, more elaborate:
DEBUGTRACE(DEBUG_LEVEL2, {
if (somethingistrue)
printf("Debugging is TRUE");
else
foo();
});
If _DEBUG is defined, then your code
is include. If not, then nothing is not compiled.