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*
C++: bool vs custom BOOL
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).
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.
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.
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.
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. )
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement