Advertisement

bool or BOOL?

Started by February 27, 2000 03:37 AM
10 comments, last by Ridcully 24 years, 6 months ago
i know that is prolly a quite unimportant question, but should i use the uppercase BOOL or bool? as i understand, BOOL is defined in windows.h and bool is a built-in type of the c++ language. because i am coding for c++ the bool type should be better, right? but i very rarely see bool in any source code, they always use BOOL. same for CHAR, char and VOID, void. so where is the difference, if any, and which type should i use? thanks ridcully
Realistically, it shouldn''t matter unless you''re doing a HUGE number of boolean operations. To the best of my knowledge, bool has slightly more overhead than BOOL (because BOOL is simply a typedef integer), but seems like it would be easier to use if you''re using C++.

My gut feel is to stick with BOOL for the two facts that A) It''s an integer, and numbers tend to move faster than different data types and B) due to its numeric nature, you can use it in formulas without it having to be cast back to an integer

In both cases, speed seems to be the only factor (and is obviously a HUGE one in game programming

-Chris
Advertisement
bool isn''t built into the C++ language, it''s a vendor specific data type. I believe both Microsoft MSVC++ and Borland C++ both have bool types. BOOL is more portable because it is just a typedef.
In VC++ 6.0, the bool type takes only one byte of memory, as apposed to the BOOL taking up 4 bytes (typical for an integer). But watch out for working with people who have other compilers (and earlier versions of VC++).

Good Luck!


- null_pointer

Edited by - null_pointer on 2/27/00 7:30:40 AM
bool is part of the c++ standard
If you are going for portability, bool is more portable that BOOL; bool is part of the c++ standard.

Mike
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown
Advertisement
Yes, bool is part of the standard, and is safer to use as a boolean type since that''s what it is. Further, it is expected that any system will have a bool type which is optimal for that system, whereas using a typedef BOOL that''s some int size, you may end up losing performance since you''re locked to some other (potentially sub-optimal) data type.

-Brian
Do not be temped by the darkside young Luke, use bool. It''s part of the C++ standard and supported by every modern compiler. bool is portable, while BOOL is Microsoft only.

--Rick
Senior Software Engineer
Dynamix
Use bool, bool is part of the ANSI C++ standard, if your compiler don''t suport it, it''s implementing an older version of the standard.
thanks for your opinions
i think i''ll switch to bool because it always turns into this nifty blue

This topic is closed to new replies.

Advertisement