the built-in type bool in C++ or the stdbool.h type in C defines TRUE and FALSE as not the size of the machine word? -


i under impression bool types either in c or c++ typdef'ed integers because "easier" handle @ machine level (size of word , not). did sizeof and, surprise, return 1 (byte). right? well, is, per own short experiment, why tell me should using integers?

just sake of interest, see wikipedia article on boolean data types c.

c++11 spec, section 3.9.1 [basic.fundamental], paragraph 6:

values of type bool either true or false. [note: there no signed, unsigned, short, or long bool types or values. — end note ] values of type bool participate in integral promotions (4.5).

section 5.3.3 [expr.sizeof], paragraph 1:

the sizeof operator yields number of bytes in object representation of operand. operand either expression, unevaluated operand (clause 5), or parenthesized type-id. sizeof operator shall not applied expression has function or incomplete type, enumeration type underlying type not fixed before enumerators have been declared, parenthesized name of such types, or lvalue designates bit-field. sizeof(char), sizeof(signed char) , sizeof(unsigned char) 1. result of sizeof applied other fundamental type (3.9.1) implementation-defined. [note: in particular, sizeof(bool), sizeof(char16_t), sizeof(char32_t), , sizeof(wchar_t) implementation-defined. (75) — end note ]

footnote (75) says:

75) sizeof(bool) not required 1

the presence of footnote suggests sizeof(bool) equals 1 on enough implementations need remind people not so.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -