If CHAR_BIT != 8, what is the size of other types?

c, sizeof

Solution

Basically, assuming CHAR_BIT is 16, would sizeof(int16_t) be equal to 1 or 2

Size of objects (as yielded by `sizeof` operator) is measured in bytes and a byte in C has `CHAR_BIT` bits.

(C99, 6.2.6.1p4) "Values stored in non-bit-field objects of any other object type consist of n x CHAR_BIT bits, where n is the size of an object of that type, in bytes."

`int16_t` type if present has a width of exactly 16-bit and no padding. This means if `CHAR_BIT == 16`, then `sizeof (int16_t) == 1`

Problem

The C standard mandates `sizeof(char)` to be 1, no matter how many bits it actually takes. Are other data-types measured in terms of bytes or chars in case these are not the same? Basically, assuming `CHAR_BIT` is 16, would `sizeof(int16_t)` be equal to 1 or 2?

Original source