But it is rather a legacy nowadays. No one should use it.
But it is rather a legacy nowadays. No one should use it.
The problem is people are confusing the definition and the usage, because this particular type "char" was supposed to hold a numerical representation of a symbol, which in case of a multi-byte encoding is not 1 byte anymore.
So, sizeof(char) is always 1, and what they trying to say is sizeof(numeric-representation-of-a-symbol) which is not a concern of the C language.
A byte is always 8 bits, and therefore contains unsigned numbers 0 to 255 inclusive.
A char is always defined to be the base size of the machine.
By definition, therefore, sizeof(char) is always 1.
However, a char is not always 1 byte. On some machines a char can hold the values 0..511, and on others 0..65535. (for example)
That definitely isn't true. Historically, bytes went from 5 to 16 bits, it was just the number of bits required to handle a character.
If you want to talk specifically about 8-bit bytes in an architecture-independent manner, use the word "octet" (which happens to be the word french people generally use).
`char` is a technically independent (though often related) datatype defined as being >= 8 bits by the ANSI standard and the definition of `sizeof(char) == 1` is an axiom of the ANSI standard, not the consequence of anything but itself, though the standard definitely seems to confound (confuse?) chars and bytes:
2 The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from the type of the operand. The result is an integer. If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant. 3 When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1. When applied to an operand that has array type, the result is the total number of bytes in the array.88) When applied to an operand that has structure or union type, the result is the total number of bytes in such an object, including internal and trailing padding.
The other reply to my comment (http://news.ycombinator.com/item?id=1666345) gets this right.
Again, apologies.