What are all the possible values of a bool value in C++?

bool types are described in section §3.9.1, Fundamental types. Of relevance here is a sentence from paragraph 6:

Values of type bool are either true or false.47

The reference footnote 47 provides some interesting additional information:

47) Using a bool value in ways described by this International Standard as “undefined,” such as by examining the value of an uninitialized automatic object, might cause it to behave as if it is neither true nor false.

This is just a direct consequence of the standard imposing no requirements on programs with undefined behaviour.

There are no size requirements on bool, other than the implicit “at least one byte” that applies to all types as a consequence of the C++ memory model.

There are also no requirements on the internal representation of bool objects, however, due to the requirements regarding integral conversions (true must convert to 1 and false to 0), implementations may be inclined to pick the same representations for true and 1, and for false and 0, since that makes such conversions unnecessary.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)