Node:Integers, Next:Integer Division, Up:Arithmetic
The C language defines several integer data types: integer, short integer,
long integer, and character, all in both signed and unsigned varieties.
The GNU C compiler extends the language to contain long long integers
as well.
The C integer types were intended to allow code to be portable among
machines with different inherent data sizes (word sizes), so each type
may have different ranges on different machines. The problem with
this is that a program often needs to be written for a particular range
of integers, and sometimes must be written for a particular size of
storage, regardless of what machine the program runs on.
To address this problem, the GNU C library contains C type definitions
you can use to declare integers that meet your exact needs. Because the
GNU C library header files are customized to a specific machine, your
program source code doesn't have to be.
These typedef
s are in stdint.h
.
If you require that an integer be represented in exactly N bits, use one
of the following types, with the obvious mapping to bit size and signedness:
INT32_MAX
, UINT8_MAX
,
INT_FAST32_MIN
, INT_LEAST64_MIN
, UINTMAX_MAX
,
INTMAX_MAX
, INTMAX_MIN
. Note that there are no macros for
unsigned integer minima. These are always zero.
There are similar macros for use with C's built in integer types which
should come with your C compiler. These are described in Data Type
Measurements.
Don't forget you can use the C sizeof
function with any of these
data types to get the number of bytes of storage each uses.