This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix <stdint.h> bugs


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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
>>   values.
> 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
integer promotions."

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
C99-compliant code):

  /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others.  */
  int check_UINT8_C:
        (-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             ebb9@byu.net
-----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

iEYEARECAAYFAkkz6wUACgkQ84KuGfSFAYDjpgCeKlf+zI3F/uXr8DDBw9OPITLb
HekAnRxlrNU5PfScLyD0jsnCr1gAUVd7
=CUFD
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]