BOOL vs bool
-
Just a quick question: what is the difference between BOOL and bool and when would I want to use one instead of the other?
-
Just a quick question: what is the difference between BOOL and bool and when would I want to use one instead of the other?
BOOL is a alias (typedef) for an integer. it works nicely with the Windows API, which, as a C API, knows nothing about "bool". it makes nice use of the fact that C (and C++) allow you to write conditionals like this:
if (iNumeric) {...}
where the condition is true if the test is a non-zero numeric value. "bool" is a native C++ type, not just an integer with a different name. i use "bool" whenever i can, just to keep things clean. with BOOL, there's the chance of accidentally using its integer properties (bVar = 5 * bTrue). -c
-
Just a quick question: what is the difference between BOOL and bool and when would I want to use one instead of the other?
as far as i know is bool a keyword from the c++ standard BOOL a data type of win32 i may be wrong.. but i think that is it.. (msdn says that bool should be in msvc++ > 4.2 an own data type and no typedef of an int, like in the old days.. and i gues BOOL is still a typedef of int) hope this helps a little bit bernhard
"There are three roads to ruin: women, gambling and technicians. The most pleasant is with women, the quickest is with gambling, but the surest is with technicians." Georges Pompidou
-
Just a quick question: what is the difference between BOOL and bool and when would I want to use one instead of the other?
(1) bool is C++ specific data type that can have values true or false BOOL is Microsoft specific keyword that is nothing but an integer. As it's defined in "windef.h"
typedef int BOOL;
So if you plan to write portable (cross-platform) C++ code, don't use BOOL, use bool instead. (2) size of bool 1 byte, whereas the same for BOOL 4 bytes (which is the size of an 'int') (3) Use 'TRUE' and 'FALSE', while using BOOL and 'true' and 'false' for 'bool'
BOOL b1 = TRUE;
bool b2 = true;(4) Since BOOL is nothing but an 'int', take extra precaution in using it. Don't simply assume that a BOOL value of other that '1' is always false. My $0.02. // Fazlul
Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com
-
(1) bool is C++ specific data type that can have values true or false BOOL is Microsoft specific keyword that is nothing but an integer. As it's defined in "windef.h"
typedef int BOOL;
So if you plan to write portable (cross-platform) C++ code, don't use BOOL, use bool instead. (2) size of bool 1 byte, whereas the same for BOOL 4 bytes (which is the size of an 'int') (3) Use 'TRUE' and 'FALSE', while using BOOL and 'true' and 'false' for 'bool'
BOOL b1 = TRUE;
bool b2 = true;(4) Since BOOL is nothing but an 'int', take extra precaution in using it. Don't simply assume that a BOOL value of other that '1' is always false. My $0.02. // Fazlul
Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com
-
Minor little point, sizeof (bool) is implementation specific. The standard even explicitly states it need not be one. I know, I know, I am being anal... Tim Smith Descartes Systems Sciences, Inc.
I guess I was talking about the implementation on Win32 platform. You are right, other compilers like GCC and some Alpha versions use 4 bytes and even 8 Bytes implementations. Thanks for the comment. // Fazlul
Get RadVC today! Play RAD in VC++ http://www.capitolsoft.com