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
booleithertrueorfalse. [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
sizeofoperator yields number of bytes in object representation of operand. operand either expression, unevaluated operand (clause 5), or parenthesized type-id.sizeofoperator 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 ofsizeofapplied 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
Post a Comment