If you've included windows.h
, then FALSE
is #defined as 0. TRUE
is #defined as 1. It is not a Boolean type, it's an integer type. Windows also defined the type BOOL
, which is actually an integer type designed to accomodate the values TRUE
and FALSE
.
The relevant sections of code in windows.h
look something like this:
#ifdef FALSE
#undef FALSE
#endif
#define FALSE 0
#ifdef TRUE
#undef TRUE
#endif
#define TRUE 1
typedef int BOOL, *PBOOL, *LPBOOL;
Windows was originally written in C, as were all of the original Windows applications. At that time, C did not have a Boolean type defined by the standard. Instead, developers were forced to define their own Boolean constants. To prevent the possible mess that could cause, Microsoft decided on a standard that would be used for all Windows applications.
If you're writing Windows applications, you may still need to use the TRUE
and FALSE
identifiers. Several of the functions defined in windows.h
either accept Boolean parameters (actually integers!) typed as BOOL
or return values of such type. C++, being strongly typed, may complain if you coerce these to the Boolean type defined in the language's standard. For consistency, I use the old identifiers in all of my calls to Windows API functions, and the true
and false
keywords now defined by the standard in all of the methods that I write myself.
There's really no reason not to use FALSE
as it is defined in windows.h
. But you shouldn't define it yourself in a proprietary header file, as others have mentioned, because there's no guarantee that the definition will remain constant over time. That could cause some pretty silly bugs, the type that qualify to appear on the Daily WTF.
Mat's answer is 100% correct that neither TRUE
or FALSE
are defined by the C or C++ standards. However, they are strictly defined by the Windows API and guaranteed not to change. Using them will not produce truly cross-platform, strictly standards-compliant C++ code, but that's rarely a concern when writing Windows apps, as neither will calling any of the other functions in windows.h
.