In VC++ we have the data type “BOOL” which can assume the value TRUE or FALSE, and we have the data type “bool”, which can assume the value true or false.
What is the difference between them and when should each data type be used?
In VC++ we have the data type “BOOL” which can assume the value TRUE or FALSE, and we have the data type “bool”, which can assume the value true or false.
What is the difference between them and when should each data type be used?
To add to what luvieere has said, you can return something other than
TRUE
orFALSE
from a function returning aBOOL
e.g.,And this is possible because a
BOOL
is essentially anint
.Please note that this is not advisable as it severely destroys the general readability of code but it is something you can come across and you will be wondering why it is so.
bool
is a built-in C++ type whileBOOL
is a Microsoft specific type that is defined as anint
. You can find it inwindef.h
:The values for a
bool
aretrue
andfalse
, whereas forBOOL
you can use anyint
value, thoughTRUE
andFALSE
macros are defined in thewindef.h
header.This means that the
sizeof
operator will yield 1 forbool
(the standard states, though, that the size ofbool
is implementation defined), and 4 forBOOL
.Source: Codeguru article
Windows API had this type before
bool
was thrown into C++. And that's why it still exits in all Windows function that take BOOL. C doesn't supportbool
data-type, thereforeBOOL
has to stay.