The types that are narrower than
int are rarely used for
ordinary variables—we declare them
int instead. This is
because C converts those narrower types to
int for any
arithmetic. There is literally no reason to declare a local variable
char, for instance.
In particular, if the value is really a character, you should declare
char! Using that narrow type can
force the compiler to truncate values for conversion, which is a
waste. Furthermore, some functions return either a character value,
or -1 for “no character.” Using
int keeps those
The narrow integer types are useful as parts of other objects, such as arrays and structures. Compare these array declarations, whose sizes on 32-bit processors are shown:
signed char ac; /* 1000 bytes */ short as; /* 2000 bytes */ int ai; /* 4000 bytes */ long long all; /* 8000 bytes */
In addition, character strings must be made up of
because that’s what all the standard library string functions expect.
ac could be used as a character string, but the
others could not be.