Jump to content
  • Advertisement

Archived

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

Possibility

is there a difference between bool and BOOL?

This topic is 6929 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 was just wondering if there is a difference between bool and BOOL. Because in VC++, bool turns a bright blue color, where as BOOL does not, it just stays the normal black font color. I know they do the exact same thing and you can use them interchangeably, but is there any difference behind the scenes? Possibility

Share this post


Link to post
Share on other sites
Advertisement
bool is a standard C++ keyword. BOOL was something invented by Microsoft to serve the same purpose.

Try to use bool if possible. Only use BOOL for compatibility with Win32.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

Try to use bool if possible. Only use BOOL for compatibility with Win32.


Why use bool, when it´s much slower on 32/64 bit cpu´s.
With BOOL you don´t have to think of the memory-alignment which should be multible by 8 ((memAdress % 8) == 0).

This will probably be more important in the furture, where the 64 bit alpha can´t handle odd memory-adresses.
This must be done in software!!!! Which is VERY SLOW...
(The 32 bit cpu can handle this exception in hardware, which is much faster, but you are still loosing a lot of speed!)

So I won´t advise the use of bool, unless you make sure to align your data!

Share this post


Link to post
Share on other sites
what''s this blind obsession with performance anyway .

Pack 4 bool''s into a struct and POOF - no alignment problems.
Oh well.

I personally prefer a bit-bool myself, saving space.
BYTE bitBool can contain 8 boolean values, and it''s fun to program.


#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

This will probably be more important in the furture, where the 64 bit alpha can´t handle odd memory-adresses.


It''s hardly a big deal. If the bool is byte 3 of a 4-byte word, I -imagine- (I''m no assembly expert, so flame away) that at worst, the compiled code would just read in the whole word (a fast operation, as you say), mask off the unwanted bits with an AND, and shift it right to get the correct 8 bits. That doesn''t seem like a lot of operations to me. 99% of tests involving a bool could possibly be optimised further anyway, avoiding the shift or the mask or both. And let''s not forget caching issues - probably the best performance increase you can get is to fit your current ''working set'' into the cache. If you go around using 4x as much memory as needed, this is less likely to happen.

Share this post


Link to post
Share on other sites
quote:

I agree with MadKeith. Why use 8 or 32 or even 64 bits to represent 1?


Because a single bit isn''t addressable. Inside a tight loop the masking operations necessary to address the individual bits can start to add up to a measurable performance hit. And remember the processor acts on byte or larger arguments, so in a sense by using bit bools you''re working against the processors (get a 32 bit value thunk it down to one bit, thunk it back up to 8 bits and repeat). A byte is at least addressable, so represents a reasonable compromise between space and speed in a computation bound process.

Of course, If you''re going to save it to disk or send it over the network, by all means, compress your bools to bit values.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well the alignment on the alpha CPU is VERY important,
in fact you can read in "Advanced Windows programming" (now called: Programming applications for Microsoft Windows) by Jeffrey Richter that this error cost upto 100 times speed (10000 %)!!!

So this could be a very important aspect of Windows programming in the furture!

Share this post


Link to post
Share on other sites
bool is a built-in type in C++ and BOOL isn''t. Before VC++5, they don''t support bool type, so MS invented themself a BOOL, which is simply
typedef int BOOL;
.... then they screw it up and make things more confused. Anyone bother to read the GetMessage() help? It returns a BOOL type, but with more than 2 different kind of values instead of true/false. Why don''t they call it a TRILEAN anyway? ;p

For other platform, I''m not sure about the memory alignment/size for a bool. I believe the compiler should know how to ''optimize'' the bool.

Stick with the bool. Use BOOL when checking returns from Windows API.

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.

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!