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 trueand false?
  • values taken: let b of type bool, 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 bool either true or false.47

the reference footnote 47 provides interesting additional information:

47) using bool value in ways described international standard “undefined,” such examining value of uninitialized automatic object, might cause behave if neither true nor false.

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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -