One good reason for this is that the compiler may very well resolve the value at compile time, depending on what stage of development you are at.
eg. you can use something like this for debugging:
int glyphIndex; ... #if CHECK_INVALID_GLYPH glyphIndex = -1; #endif switch (glyphIndex) ...
The compiler knows for sure that glyphIndex is -1 here, so it is no worse than a constant. Alternatively, you can write it as follows:
#if CHECK_INVALID_GLYPH const int glyphIndex = -1; #else int glyphIndex = GetGlyph(); #endif
In fact, you would not want to change the body of the switch statement so that you can make small changes like this, and the compiler is quite capable of streamlining the code to exclude parts that will never be executed anyway.
source share