Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Confused about C99 _Bool and <stdbool.h>

807578Oct 30 2007 — edited Oct 31 2007
C99 defines the _Bool type, which seems like a good language feature, but it does not seem to be designed very well.

The main point of confusion I have is that boolean expressions apparently do not give a _Bool type. These expressions both give a size of 4: sizeof(1==1), sizeof(true). What is the point of having a boolean type if the languages doesn't even use it for boolean values? C++ is consistent is boolean sizes, so maybe the C99 boolean types are meant more for C++ function compatibility.

Also, why do the true and false values in stdbool.h not include casts to actually be defined as Bool types? Even if boolean expressions are not the Bool type, shouldn't sizeof(true) match sizeof(_Bool)?

My guess is that Bool is not implemented very well because it would break a lot of C code that assumes 'int' for boolean values. Maybe the next standard should also define types like bool8t and bool32_t, so that the established int-booleans can work along with a 1-byte _Bool type.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2007
Added on Oct 30 2007
2 comments
2,210 views