Still more ways of saying the same thing. Why so many?
Because each was invented by different people at different times to solve different problems.
BOOL is the oldest one. Its definition is simply
typedef int BOOL;
The C programming language uses “int” as its boolean type, and Windows 1.0 was written back when C was the cool language for systems programming.
typedef BYTE BOOLEAN;
This type was introduced by the OS/2 NT team when they decided to write a new operating system from scratch. It lingers in Win32 in the places where the original NT design peeks through, like the security subsystem and interacting with drivers.
Off to the side came
typedef short VARIANT_BOOL; #define VARIANT_TRUE ((VARIANT_BOOL)-1) #define VARIANT_FALSE ((VARIANT_BOOL)0)
This was developed by the Visual Basic folks.
-1 to represent “true”
0 to represent “false”,
VARIANT_BOOL was designed to preserve this behavior.
Common bug: When manipulating
VT_BOOL, and you want to set a boolean value to “true”,
you must use
Many people mistakenly use
which are not the same thing as
You can cause problem with scripting languages if you get them confused.
(For symmetry, you should also use
All three have the same numerical value, however.
Consequently, a mistake when manipulating “false” values is not fatal.)
Newest on the scene is
bool, which is a C++ data type
that has the value
You won’t see this used much (if at all) in Win32 because Win32 tries to
(Note that C-compatible isn’t the same as C-friendly. Although you can do COM from C, it isn’t fun.)