To use or not to use bool?
This has been on my mind recently. I love using bool, bool variables and bool functions (so I get to return true instead of 1). Is there a reason not to? Do bool''s have a higher performance hit then an int (doubting, but it''s better to know for sure)? Also, I do recall something about bool being something microsoft came up with (it''s been a long time, I dont know how true this is) but if that''s the case, it''s not an issue. I have no intention of ever making any of my program''s multi-platform so it all works out
If you can read this, All your base are belong to us!
Well, as far as I know bool is part of the C++ standard.
It depends on how you declare it, there is BOOL and then there is bool. BOOL is defined in VC++ and is not part of any standard.
The only drawback to using bool that I know of is no specific error code if a function fails.
Jason Mickela
ICQ : 873518
E-Mail: jmickela@sbcglobal.net
------------------------------
"Evil attacks from all sides
but the greatest evil attacks
from within." Me
------------------------------
It depends on how you declare it, there is BOOL and then there is bool. BOOL is defined in VC++ and is not part of any standard.
The only drawback to using bool that I know of is no specific error code if a function fails.
Jason Mickela
ICQ : 873518
E-Mail: jmickela@sbcglobal.net
------------------------------
"Evil attacks from all sides
but the greatest evil attacks
from within." Me
------------------------------
bool is just a nice way to look at the int version of true/false states. I like to keep using just ints, then can define TRUE = 1, FALSE = 0. That way can do things like multiply the state, whereas it does not make sense to multiply bool * int.
The only advantage over using ints is that a bool is == a char. So a bool is smaller than an int. Other than that, it''s neat to return TRUE rather than 1
quote:Original post by griffenjam
Well, as far as I know bool is part of the C++ standard.
The C standard as well (since 1999), although many C compilers haven''t been updated yet (like MSVC''s C compiler, it won''t let you use bool).
Also, a bool isn''t always one byte. It is normally, but the absolute standard doesn''t set a size in bytes for any type.
[Resist Windows XP''s Invasive Production Activation Technology!]
quote:Original post by griffenjam
BOOL is defined in VC++ and is not part of any standard.
BOOL isn''t a VC++ specific type. It''s a typedef in the windows headers. The reason for it is that at the time the Windows headers where written (for the first time) the bool-type wasn''t in the standard.
Excellent, so there should be no excuse for me to not using bool (unless I dont want to)
If you can read this, All your base are belong to us!
If you can read this, All your base are belong to us!
I remember reading that the size of a bool was to be one byte - so it''s _bad to use bool''s on a 32bit machine. It''ll have less trouble with BOOLs (since they''re DWORDs). 99.99999% of the time it probably wouldn''t matter, but BOOLs are ever-so slightly faster.
They were mostly added so that you could overload comparative operators properly (==, !=, <, etc...).
They were mostly added so that you could overload comparative operators properly (==, !=, <, etc...).
That''s why I typedefed my own version of bool, so I can select exactly what size I want it to be and have it apply to my entire library.
[Resist Windows XP''s Invasive Production Activation Technology!]
[Resist Windows XP''s Invasive Production Activation Technology!]
In fact, in some CPUs like spark ones.. there are special registers to store and operate bool. So it`s faster.
If brute force does not solve your problem....you''re not using enough!
If brute force does not solve your problem....you''re not using enough!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement