Home > Backend Development > C++ > What Determines the Size of a `bool` in C ?

What Determines the Size of a `bool` in C ?

Linda Hamilton
Release: 2024-12-18 19:10:17
Original
148 people have browsed it

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.
Copy after login

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.
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template