Jump to content
  • Advertisement
Sign in to follow this  
Basiror

C++: bool vs custom BOOL

This topic is 4928 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

i have a seperate header file with all the typedefs in it (*luckily*)

this way I stay compiler and platform independent concerning datatype size

is there some sort of compiler option to make sure bool is 32 bit aligned?


tztz how can one make something that important implementation specific *gr*

Share this post


Link to post
Share on other sites
Advertisement
Why is it so important that bool be 32-bit aligned? Efficiency isn't really a good reason (in most cases). Micro-optimizing using typedefs like that is a relic of the past when it comes to C/C++ (unless you're targeting some kind of ancient platform).

Share this post


Link to post
Share on other sites
Quote:
Original post by Basiror
i have a seperate header file with all the typedefs in it

this way I stay compiler and platform independent concerning datatype size

is there some sort of compiler option to make sure bool is 32 bit aligned?


tztz how can one make something that important implementation specific *gr*


That's *why* its implementation specific, so that it's the appropriate size and format on all platforms and processors.

The compiler will do its best to make the data aligned on platforms that have an abundance of memory. Check the project settings.

Share this post


Link to post
Share on other sites
Quote:
Original post by Basiror
is there some sort of compiler option to make sure bool is 32 bit aligned?


There usually is a #pragma or -- for gcc an __attribute__ that controls that, check your documentation.

Quote:
tztz how can one make something that important implementation specific


Because it's precisely up to the compiler implementers to know what is the best solution for the platform they are writing a compiler for. You wouldn't want to enforce in the language specifications that a given data type must be XYZ-aligned, particularly if that's is impossible on platform ABC due to hardware particularities.

Share this post


Link to post
Share on other sites
Windows API uses BOOL because programs written in C need to be able to interface with it. There is absolutely no reason to use BOOL in your C++ programs.

Share this post


Link to post
Share on other sites
There's also no way to get the built-in comparison operators to return BOOL -- they all use bool. And any overloaded comparison operator shouldn't return BOOL because that violates the principal of least astonishment. ( Every standard comparison returns bool, so yours should too. )

Share this post


Link to post
Share on other sites
Quote:
Original post by Shannon Barber
In C++ you should always use the built-in bool (and true & false) if that's what you mean.


The one place to be careful is std::vector<bool>
Scroll down to the What About bool? section of this Guru of the Week article for a good explanation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!