Related to this and this.

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 bools themselves or between bools and other integer types handled?

1

There are 1 best solutions below

5
On

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 type bool are true and false.

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 type int, with false becoming zero and true becoming one.