Defining giving a warning in C++

c++, visual-studio-2010

Solution

Without seeing the code, I suspect you have the following construct:

if (inDebugMode)
{
}

which will always be `true`, hence the warning.

Recommend using the preprocessor instead of `if`:

#define inDebugMode 1

#if inDebugMode
#endif

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`:

cl.exe /DinDebugMode=1 ...

but you need to ensure you rebuild all sources if you choose the command line option, not just the changed sources.

Problem

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?

Original source