c++11 - What are all the possible values of a bool value in C++? -
the question not obvious seems, , have trouble finding information bool type in standard.
according c++11 standard, guarantees associated bool type regards to:
- storage: how space take, ignoring alignment? there requirement value stored represent
trueandfalse? - values taken: let
bof typebool, assertion(b == true) || (b == false)hold?(false < true)well-formed, , hold?
bool types described in section §3.9.1, fundamental types. of relevance here sentence paragraph 6:
values of type
booleithertrueorfalse.47
the reference footnote 47 provides interesting additional information:
47) using
boolvalue in ways described international standard “undefined,” such examining value of uninitialized automatic object, might cause behave if neithertruenorfalse.
this direct consequence of standard imposing no requirements on programs undefined behaviour.
there no size requirements on bool, other implicit "at least 1 byte" applies types consequence of c++ memory model.
there no requirements on internal representation of bool objects, however, due requirements regarding integral conversions (true must convert 1 , false 0), implementations may inclined pick same representations true , 1, , false , 0, since makes such conversions unnecessary.
Comments
Post a Comment