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:
- ISO C89/C90, not C99.
- No headers not defined in the ISO standard.
- No preprocessor symbols not defined in the ISO standard.
- No type-size assumptions not specified in the ISO standard.
- No proprietary vendor symbols.
I see other questions similar to this in StackOverflow, but no answers yet that do not violate one of the above constraints. I’m not sure it’s possible without resorting to platform symbols.
Yes you can.
The header file
limits.hshould be part of C90. Then I would test through preprocessor directives values ofSHRT_MAX,INT_MAX,LONG_MAX, andLLONG_MAXand set typedefs accordingly.Example: