Fix UINT{8,16}_C

Eric Blake ebb9@byu.net
Mon Jul 3 12:10:00 GMT 2006


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

According to Corinna Vinschen on 7/3/2006 3:41 AM:
>   
> 
> I have checked the stdint.h headers on glibc 2.3.4 and 2.4, as well as
> on Solaris 10, NetBSD, FreeBSD and OpenBSD.  Only FreeBSD and OpenBSD
> define them as just x, all others as x##U, one way or the other.

And gnulib rejects Solaris 10 and glibc's versions as buggy as well:

http://lists.gnu.org/archive/html/bug-gnulib/2006-06/msg00118.html

> 
> ISO/IEC 9899:TC2 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf)
> has the following to say:
> 
>   7.18.4.1 Macros for minimum-width integer constants
> 
>   The macro INTN_C(value) shall expand to an integer constant expression
>   corresponding to the type int_leastN_t.

The problem is that there is no integer constant expression for unsigned
char; instead, you get an integer constant expression for the type that
unsigned char promotes to.  Therefore, UINT8_C should give an int, not
unsigned int.

This snippet from gnulib is valid C code, but fails if you use the wrong
type specifier:

  /* 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;
  int check_UINT16_C:
	(-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1;


- --
Life is short - so eat dessert first!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEqQlJ84KuGfSFAYARAiZ6AJ96BYisYJGTcK89Nbc+LWzeaaOCTQCbBdy6
fvwEMp2hXBTtEsSaVSOg30w=
=ddci
-----END PGP SIGNATURE-----



More information about the Cygwin-patches mailing list