Linux-Hams archive - July 1998: sizeof()

sizeof()

Mike Bilow (EEST)
Sun, 05 Jul 98 18:15:00 -0000


Matti Aarnio wrote in a message to Mike Bilow:

MA> The C specification says basically that following
MA> relations should hold true:

MA> sizeof(char) <= sizeof(short) <= sizeof(int) <=
MA> sizeof(long)

MA> 16-bit 8086, PDP-11:
MA> 8, 16, 16, 32
MA> 32-bit 80386 (UNIX mode):
MA> 8, 16, 32, 32
MA> 64-bit Alpha (UNIX mode):
MA> 8, 16, 32, 64
MA> CRAY:
MA> 64, 64, 64, 64

MA> This last one is in fact what troubles Samba folks when
MA> they try to get the server to work at CRAY UNICOS...

I loathe public discussions of this issue, but it is worth pointing out that
ANSI C actually requires that "sizeof(char)" be strictly 1 in all cases. If
the machine has no byte-wide storage capability, then the compiler is obliged
to perform whatever tricks are needed to satisfy the requirement consistently.
If you want to know how many bits there are in a "char", use "CHAR_BIT" from
LIMITS.H.

-- Mike