Re: sizeof(char

Richard Gooch (rgooch@atnf.CSIRO.AU)
Fri, 23 Jan 1998 13:49:25 +1100


Richard B. Johnson writes:
> On Thu, 22 Jan 1998, Marc Lehmann wrote:
>
> >
> > it might be worth to note that sizeof(char)==1, ALWAYS, on every
> > architecture, on all iso c compliant systems.
> >
> > char _is_ the smallest addressable unit, and sizeof() doesn't
> > measure bytes but storage units, so this equation holds without
> > problems.
> >
>
> You are correct. However, the 'C' standard didn't recognize that it
> is possible to address a single bit in memory on several architectures.
> This means that, interpreted literly, sizeof(8BIT_OBJECT) would be 8!
> Then there is the problem with nibble-based systems like the '360. The
> smallest addressable storage unit is 4 bits. This would make such
> an interpretation of sizeof(8BIT_OBJECT) == 2.
>
> Once 'C' is ported to an old IBM/360 this problem will have to be
> addressed <grin>. In the meantime, it is assumed that the smallest
> storage unit is 8 bits even though a char object isn't necessarily
> this size.

>From the New Testament:

A7.4.8 Sizeof Operator
The sizeof operator yields the number of bytes required to store an
object of the type of its operand. [...] When sizeof is applied to a
char, the result is 1. [...] The operator may not be applied to [...]
a bit-field.

So, char is always 1 byte, and is the smallest type you can pass to
sizeof.

Regards,

Richard....