I must be missing something.

The C99 standard says the range for int and an unsigned int MUST be at least 
[-32767,+32767] and [0,65535], respectively. This means they are minimum 16 
bits wide. Similarly, looking at the spec for LONG_MIN, LONG_MAX, and 
ULONG_MAX, the standard says that a long and unsigned long MUST be minimum 32 
bits wide. The standard makes no claim that they can't be wider, but seems 
_very_ clear on the minimum widths.

However, when I look at <stdint.h>, I see the following typedefs:
ISO C99: 7.18 <stdint.h>
        typedef unsigned int uint32_t;
        typedef int int32_t;

This has me scratching my head, because on platforms where an int is 16 bits 
wide you have a type called "int32_t" that contrary to its name is 16 bits wide!

It seems to me the typedefs in <stdint.h> should be:
        typedef unsigned long uint32_t;
        typedef long int32_t;
So then by the spec we are guaranteed that an int32_t will be at least 32 bits 
wide.

This seems to be a pretty serious error in terms of portability. But given 
these typedefs have been in <stdint.h> for a long time they must be OK for some 
reason I can't see.

Can somebody please shed some light on this for me?



Reply via email to