Reputation: 28510
If I define
bool y = true;
bool n = false;
is the bit-wise content of the 1-byte storage of y
and n
mandated by the standard? If so, which are those two contents? If not, then how is the comparison between bool
s themselves or between bool
s and other integer types handled?
Upvotes: 1
Views: 108
Reputation: 22394
Standard does not require any bit representation for bool
, it only requires that there are two values true
and false
- and in particular, it doesn't seem to require that there is only one representation for each value ([basic.fundamental]#10):
Type
bool
is a distinct type that has the same object representation, value representation, and alignment requirements as an implementation-defined unsigned integer type.
The values of typebool
aretrue
andfalse
.
It is required that true
is mapped to 1
and false
is mapped to 0
when converting bool
to int
([conv.prom]#6):
A prvalue of type
bool
can be converted to a prvalue of typeint
, withfalse
becoming zero andtrue
becoming one.
Upvotes: 3