Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Necrosis

To use or not to use bool?

This topic is 6170 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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
------------------------------

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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...).

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!