Jump to content
  • Advertisement

Archived

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

prgrmmr

Did You Know? that BOOL is not the same as bool?

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

Yes, that is. You can use FLOAT instead of FLOAT, LONG instead of long, but: if you use ''bool'' the you use a logical value, when you use ''BOOL'' it is treated as a 32-bit integer. (INT) sorry if you has already known it, but I discovered it some days before, and found it interesting.

Share this post


Link to post
Share on other sites
Advertisement
BOOL is the same as bool if I do this:

typedef bool BOOL;

It really just depends on however it is defined, since BOOL is not standard C or C++

Share this post


Link to post
Share on other sites
i mean the general definitions, and C++. I know the typedef
but I believe that ( until know ) that they are the same.

so I thought there is already a typedef bool BOOL; in some header file, because there is for the other types. So if you write long, or LONG they''re the same.

and the only reason I posted it, because I may help other programmers, who doesn''t know this, I wonder how can the size a logical value be 4 bytes.

Share this post


Link to post
Share on other sites
The reason there is a BOOL is because like someone said: bool does not exist in C so Microsoft needed a own type. However, as bool is only 1 byte long (in comparision to the 4 byte BOOL), it can cause misalignment among structure members. If your compiler has optimizing on, this code would generate the same 8 byte structure:


struct A
{
bool var1;
int var2;
};

struct B
{
BOOL var1;
int var2;
}


The int takes four bytes, but since the bool''s 1 byte offset would make the int''s position not evently divisible by 4 in memory, the compiler instead adds a 3 byte padding in between. In some speed-sensitive cases there is therefore a logical use of BOOL, although it may seem unnecessary because the compiler can handle it.

I''d recommend though that you place your 1 byte bools last in your structures and group them together with 1 byte chars and the like. That way you''ll not add unnecessary padding space.

Share this post


Link to post
Share on other sites
quote:
Original post by Kippesoep
This is because there is no C datatype known as bool, that''s a C++ datatype.


Wasn''t bool added as a datatype recently in C? Anyways, at least there was no bool datatype in C when BOOL was typedefed.

Share this post


Link to post
Share on other sites
quote:
Original post by Brother Bob
Wasn't bool added as a datatype recently in C? Anyways, at least there was no bool datatype in C when BOOL was typedefed.



Yeah, in C99 the keyword is _Bool.

500 Error.

[edited by - microdot on January 31, 2003 11:02:34 AM]

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!