Erik Wikström wrote:
>
Because 1 is the smalles possible value. Theoretically a bool does not
need to take more space than on bit, but due to alignment requirements
and such that would leave at least 7 bits in that byte unused, so the
effective space used would still be at least one byte. Note though that
the 1 of sizeof(bool) does not mean 1 byte, but rather a piece of memory
as large as a char (which is the smallest addressable unit in C++),
which just happens to be one byte on most machines.
The above is wrong on several accounts.
First, byte in C++ is defined in terms of char. A char
variable by definition in the language is one byte.
This unfortunately is a major defect in C++ portability.
char plays double duty:
1. It's the native character type.
2. It's the smallest addressable storage unit.
When all the world is eight bit ascii this is not an
issue. It's problematic when the native character
is LARGER than the minimal addressable storage
(for example a machine with addressable units
of 8 bits, but the native char wants to be 16).
wchar_t is a poor substitute as there are a number
of important interfaces that do not have wchar_t
analogs. You have to kludge it by inventing
a multibyte (conversion of the wchar_t type to
a sequence of chars) even when such a thing
doesn't uniquely exist.
Further, no C++ type can be less than the byte
size (sizeof char). This is also fundamanetal.
It has nothing to do with alignment. It has to
do with the fact that C++'s pointer behavior
assumes that things aren't smaller than char.