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;
}
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;
}
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.
Yes. In practice, you can use sizeof(bool) * CHAR_BIT
as your guide to knowing how many bits are available.
From C++98, § 9.6.3
A bit-field shall have integral or enumeration type (3.9.1).
From C++98, § 3.9.1.7
Types bool, char, wchar_t, and the signed and unsigned integer types are collectively called integral types