3 ms·
More accurately, sizeof(char) is always 1. This is simply because sizeof returns the size of the object measured in terms of the equivalent number of chars (rat
by Koshkin 10y ago
More accurately, sizeof(char) is always 1. This is simply because sizeof returns the size of the object measured in terms of the equivalent number of chars (rather than 'bytes').
- John23832 10y agoThat's not true. sizeof(char) returns 1 because the size of a char in that implementation is 1 byte and C doesn't directly address bits.
- Koshkin 10y agoWell, according to the Wikipedia article about sizeof, In the programming languages C and C++, the unary operator sizeof generates the size of a variable or datatype, measured in the number of char size storage units required for the type. As such, the construct sizeof (char) is guaranteed to be 1.
- jwilk 10y agoPerhaps your notion of what a byte is different, but according to the C99 standard: - sizeof returns size in bytes; - sizeof (char) == 1; - one byte has CHAR_BIT bits; - CHAR_BIT >= 8.
- AnimalMuppet 10y agoSo per C99, a byte can have more than 8 bits? My mind boggles...
- Someone 10y agoFor 36-bit CPUs, the 9-bit byte was a natural choice (as was storing 6 characters of a more limited character set in a 36-bit word)
- AnimalMuppet 10y agoAh, yes, 36-bit. I had forgotten about that, despite my mother having worked on such systems.
- John23832 10y ago> - one byte has CHAR_BIT bits; Can you link a reference to this? Seems backwards/weird.