Eric Blake | 2 Jul 23:00
Gravatar

Fix UINT{8,16}_C


According to POSIX, UINT{8,16}_C should result in an integer constant with
"the same type as would an expression that is an object of the
corresponding type converted according to the integer promotions."  And
according to C, unsigned char promotes to signed int, when int is wider
than char.  Gnulib now tests for bugs in stdint.h, and these are the
remaining two issues that makes cygwin's version non-compliant:

2006-07-02  Eric Blake  <ebb9 <at> byu.net>

	* include/stdint.h (UINT8_C, UINT16_C): Unsigned types smaller
	than int promote to signed int.

--
Life is short - so eat dessert first!

Eric Blake             ebb9 <at> byu.net
Index: cygwin/include/stdint.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/stdint.h,v
retrieving revision 1.6
diff -u -p -r1.6 stdint.h
--- cygwin/include/stdint.h	23 May 2005 13:13:00 -0000	1.6
+++ cygwin/include/stdint.h	2 Jul 2006 21:01:39 -0000
@@ -1,6 +1,6 @@
 /* stdint.h - integer types

-   Copyright 2003 Red Hat, Inc.
(Continue reading)

Corinna Vinschen | 3 Jul 11:41

Re: Fix UINT{8,16}_C

On Jul  2 15:02, Eric Blake wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> According to POSIX, UINT{8,16}_C should result in an integer constant with
> "the same type as would an expression that is an object of the
> corresponding type converted according to the integer promotions."  And
> according to C, unsigned char promotes to signed int, when int is wider
> than char.  Gnulib now tests for bugs in stdint.h, and these are the
> remaining two issues that makes cygwin's version non-compliant:
> [...]
> @@ -169,8 +169,8 @@ typedef unsigned long long uintmax_t;
>  #define INT32_C(x) x ## L
>  #define INT64_C(x) x ## LL
>  
> -#define UINT8_C(x) x ## U
> -#define UINT16_C(x) x ## U
> +#define UINT8_C(x) x
> +#define UINT16_C(x) x
>  #define UINT32_C(x) x ## UL
>  #define UINT64_C(x) x ## ULL
>  

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.

ISO/IEC 9899:TC2 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf)
has the following to say:

(Continue reading)

Eric Blake | 3 Jul 14:10
Gravatar

Re: Fix UINT{8,16}_C


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.  */
(Continue reading)

Corinna Vinschen | 3 Jul 14:31

Re: Fix UINT{8,16}_C

On Jul  3 06:10, Eric Blake wrote:
> -----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
(Continue reading)


Gmane