C++ Migration Guide

Boolean Type

The boolean types--bool, true, and false--are controlled by the presence or absence of boolean keyword recognition in the compiler:

Turning on the keywords in compatibility mode is a good idea, because it exposes any current use of the keywords in your code. (Note: Even if your old code uses a compatible definition of the boolean type, the actual type is different, affecting name mangling. You must recompile all old code using the boolean type in function parameters if you do this.)

Turning off the boolean keywords in standard mode is not a good idea, because the C++ standard library depends on the built-in bool type, which would not be available. When you later turn on bool, more problems ensue, particularly with name mangling.

The compiler predefines the macro _BOOL to be 1 when the boolean keywords are enabled. It is not defined when they are disabled. For example:


// define a reasonably compatible bool type
#if !defined(_BOOL) && !defined(BOOL_TYPE)
    #define BOOL_TYPE           // Local include guard
    typedef unsigned char bool; // Standard-mode bool uses 1 byte
    const bool true = 1;
    const bool false = 0;
#endif

It is not possible to define a boolean type in compatibility mode that works exactly like the new built-in bool type. This is one reason why a built-in boolean type was added to C++.