Home >Backend Development >C++ >What Determines the Size of a `bool` in C ?
Implementation-Defined Size of bool in C Standard
Although the C language standard explicitly states the sizes of fundamental types like char, signed char, and unsigned char to be 1 byte each, the definition of sizeof(bool) is left to implementers' discretion.
The standard emphasizes this ambiguity in §5.3.3/1:
sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1; the result of sizeof applied to any other fundamental type is implementation-defined.
This means that the size of bool is not guaranteed to be 1 byte, and the standard includes a footnote (69) explicitly indicating:
sizeof(bool) is not required to be 1.
Therefore, the implementation may decide the size of bool based on various factors, such as architecture or platform constraints. As a result, sizeof(bool) can vary across different compilers and systems.
The above is the detailed content of What Determines the Size of a `bool` in C ?. For more information, please follow other related articles on the PHP Chinese website!