I was reading C++ Primer and came across a table containing the minimum guaranteed size of data types of C++, in that it was written that the minimum size of bool is not guaranteed.
Is there any specific reason for it?
1 Answer
Theoretically, a boolean's size need only be a single bit but in memory allocation, types need to be aligned in a way to be compatible with other types and filler bitsare sometimes used on different compilers and computer architectures so that the smallest capsule to store any data type is a byte.
Why is a boolean 1 byte and not 1 bit of size?
As per the last comment, I should add this quote from the Wikipedia article on byte:
The byte /ˈbaɪt/ is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer[1][2] and for this reason it is the smallest addressable unit of memory in many computer architectures.
3 Comments
bool also have to be addressable (using e.g. the address-of operator &) which also means it has to be at least the smallest addressable unit of the system, which usually is a byte.bool. The question is why the minimum size it not guaranteed.
bool, so why bother stating that minimum size again?