No, the C standard specifies minimum sizes for integral types but makes no guarantee on maximum sizes.
An implementation shall provide intN_t
types if types of that size are available. I only mention that since you had a cross-platform tag - an implementation that does not have a type of the correct bit width does not need to provide those types.
You can generally select (with setting defines with, for example, cc -D_INT16_IS_INT
and #ifdef
s) the correct type to use for a specific bit size. You can work out the required defines for each platform you want to support with C code using CHAR_BIT
and sizeof()
.
The relevant section of the c1x draft (n1362) is:
7.18.1.1 Exact-width integer types
The typedef name intN_t
designates a signed integer type with width N
, no padding bits, and a two’s complement representation. Thus, int8_t
denotes a signed integer type with a width of exactly 8 bits.
The typedef name uintN_t
designates an unsigned integer type with width N
. Thus, uint24_t
denotes an unsigned integer type with a width of exactly 24 bits.
These types are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a two’s complement representation, it shall define the corresponding typedef names.
Regarding the selection of types, something like this should suffice:
#ifdef INT32_IS_SHORT
typedef short INT32
#endif
#ifdef INT32_IS_INT
typedef int INT32
#endif
#ifdef INT32_IS_LONG
typedef long INT32
#endif