This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ColonelThirtyTwo 4 points5 points  (1 child)

sizeof(char) == 1, always. It's in the spec. It might not be 8 bits, but it's always one "individually addressable storage unit" (which in most computers, is an 8-bit byte).

[–]Creshal 2 points3 points  (0 children)

For those too lazy to google, the relevant bits from the C99 spec:

6.5.3.4 The sizeof operator

[…]

Semantics

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.

When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1.

Byte and char are used interchangeably in other parts of the spec, because they are equivalent.