Fix <stdint.h> bugs
Wed Dec 3 16:30:00 GMT 2008
-----BEGIN PGP SIGNED MESSAGE-----
According to Ralf Corsepius on 11/30/2008 11:35 PM:
>> * UINT8_C and UINT16_C wrongly expanded to unsigned values. If the
>> types uint_least8_t and uint_least16_t are narrower than int, they
>> promote to signed int, and so these macros should expand to signed
> Hmm? Why should they promote to signed int?
> SUSv3 says:
> "The macro UINTN_C( value) shall expand to an integer constant
> expression corresponding to the type uint_least N _t."
And the SUSv3 folks later corrected that by an interpretation, to match
the C99 defect report that also corrected this issue. The wording in the
upcoming POSIX 2008 release adds the additional text:
"Each invocation of one of these macros shall expand to an integer
constant expression suitable for use in #if preprocessing directives. The
type of the expression shall have the same type as would an expression
that is an object of the corresponding type converted according to the
Since uint_least8_t is always smaller than int, the C integer promotion
rules states that it promotes to signed int.
Gnulib even enforces this, using the following compile-time check (in
other words, making UINT8_C give an unsigned value fails to compile this
/* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */
(-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1;
Don't work too hard, make some time for fun as well!
Eric Blake email@example.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the Newlib