I want to declare a debug flag is on or off in these both ways:
#define inDebugMode true
or
const bool inDebugMode = true;
The compiler in Visual Studio 2010 always gives a warning:
warning C4127: conditional expression is constant
Why is that? How can I declare it correctly?
Without seeing the code, I suspect you have the following construct:
which will always be
true, hence the warning.Recommend using the preprocessor instead of
if:This will remove the warning and prevent the debugging code being compiled when unrequired. Note you can also specify the value of a macro via the compiler switch
/D:but you need to ensure you rebuild all sources if you choose the command line option, not just the changed sources.