char
is always a byte , but it's not always an octet. A byte is the smallest addressable unit of memory (in most definitions), an octet is 8-bit unit of memory.
That is, sizeof(char)
is always 1 for all implementations, but CHAR_BIT
macro in limits.h
defines the size of a byte for a platform and it is not always 8 bit. There are platforms with 16-bit and 32-bit bytes, hence char
will take up more bits, but it is still a byte. Since required range for char
is at least -127 to 127 (or 0 to 255), it will be at least 8 bit on all platforms.
ISO/IEC 9899:TC3
6.5.3.4 The sizeof operator
- ...
- The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. [...]
- When applied to an operand that has type
char
, unsigned char
, or signed char
, (or a quali?ed version thereof) the result is 1. [...]
Emphasis mine.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…