Is there a reliable way to declare typedefs for integer types of fixed 8,16,32, and 64 bit length in ISO Standard C?
When I say ISO Standard C, I mean that strictly:
Yes you can.
The header file limits.h
should be part of C90. Then I would test through preprocessor directives values of SHRT_MAX
, INT_MAX
, LONG_MAX
, and LLONG_MAX
and set typedefs accordingly.
Example:
#include
#if SHRT_MAX == 2147483647
typedef unsigned short int uint32_t;
#elif INT_MAX == 2147483647
typedef unsigned int uint32_t;
#elif LONG_MAX == 2147483647
typedef unsigned long uint32_t ;
#elif LLONG_MAX == 2147483647
typedef unsigned long long uint32_t;
#else
#error "Cannot find 32bit integer."
#endif