Possible Duplicate:
C++ bitfield packing with bools
Is it guaranteed to be safe to use C++'s bool
keyword inside a bitfield definition?
Something like:
struct flags {
bool a : 1;
bool b : 1;
}
Boolean variables are stored as 16-bit (2-byte) numbers, but they can only be True or False.
Both C and C++ allow integer members to be stored into memory spaces smaller than the compiler would ordinarily allow. These space-saving structure members are called bit fields, and their width in bits can be explicitly declared.
From C++03 9.6 "Bit-fields":
A bit-field shall have integral or enumeration type (3.9.1). It is implementation-defined whether a plain (neither explicitly signed nor unsigned) char, short, int or long bit-field is signed or unsigned. A bool value can successfully be stored in a bit-field of any nonzero size. ...
If the value true or false is stored into a bit-field of type bool of any size (including a one bit bit-field), the original bool value and the value of the bit-field shall compare equal. ...
3.9.1/7 "Fundamental types" specifies that bool
is an integral type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With