I've looked through the book, but apparently they use the _DEBUG macro as well. 8[ (they mention the non-const bool debug flag as an alternative though, in case you want to have the debug code in the release-build...)
I'm sorry, I must have picked it up somewhere else. the argument being something like
"There is more error-checking for if-statements. no compiler will say anything against something like
Code:
#ifdef _DEBUG
int i=0;
#endif
cout <<i;
but every compiler will stop at
Code:
if (debug) {
int j=0;
}
cout << j;
or similar. (returns inside the debug code etc. as well)"
It must have sounded perfectly logical when I heard it or I wouldn't have remembered it. Too bad I (apparently) don't know where it's from :-(
EDIT: of course the above example is not really "error-checking", as the if-statement just has it's own stack-frame. The int variable thus doesn't even exist in the second case when it is needed. But there are other examples, like a 'return'. If the only return is in an if-block, the compiler will notice that there should be a return value even without this 'if'.
EDIT2: there is a lot that can go wrong with preprocessor commands. for example
Code:
if (something) {
cout<<"can't do that"<<endl;
#ifdef _DEBUG
cout<<"so line 99 didn't work after all..."<<endl;
}
#endif
in a more complex situation this might not be as simple to see.
Personally I will use something like:
Code:
#ifdef _DEBUG
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif