in the Debug.h file, I have the following:
#ifdef DEBUG_FLAG
#define DEBUG(msg) std::cerr << #msg << std::endl
#else
#define DEBUG(msg) for(;true==false;)
#endif
In other places, I may write something like
void process (Data data)
{
DEBUG("Function 'process' starts");
// Blah blah
// More blah blah...
DEBUG("Function 'process' returns");
}
Will the compiler optimize away the for(;true==false;); ?
Also, is this kind of practice okay? If not, what would be a better way?
Thanks!
Here’s an alternative, that uses the compiler’s dead code removal:
The
dbgloginstance is aostreamwrapper that detects if the log line ended with a newline or not. If not, it adds one.Now, you can add a simple message like this (note, the newline is optional):
Or, if you want to add more debugging information: