When it comes to C++...
bool is a built-in C++ native type which takes the built-in values true or false. By built-in, I mean that the C++ compiler understands bool, true, and false as key words.
But with C...
Before C99, there was no boolean type in C. So you had to use one of the integral types to represent a boolean value. The one used by the Windows API (which is a C API, not a C++ API) is BOOL.
BOOL is a typdef of int, and TRUE and FALSE are #defined as 1 and 0, to work with BOOL.
(I think that int is used rather than short, char, etc because of the way C promotes values to ints when comparing. It's been a while since I read about this, and I am a C++ programmer, but I believe a C program will deal with this code
1 2 3 4 5 6 7
|
char ch1 = 'a';
char ch2 = 'b';
// etc
if(ch1 == ch2) {
// etc
|
by promoting ch1 and ch2 to integers and then comparing them (C promotes everthing that can fit into an int to an int. 64-bit intergers, etc. are treated a bit differently.)
So you might as well use int for BOOL is most cases (unless you have so many of them you're worried about memory, I guess.)
C++ does not promote before the comparison unless types are different.)
C99 has its own boolean type: _Bool. But this is usually #defined to bool. And true and false are #defines of 1 and 0.
Andy