This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: c99 stdint.h question
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Steve Ellcey <sje at cup dot hp dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 10 Apr 2009 18:33:36 +0000 (UTC)
- Subject: Re: c99 stdint.h question
- References: <200904101723.n3AHNdU20165@lucas.cup.hp.com>
On Fri, 10 Apr 2009, Steve Ellcey wrote:
> $ cat x.c
> typedef unsigned char uint8_t;
> void test_exact (void)
> {
> __typeof__(((255u))) a;
> __typeof__((uint8_t)0 + 0) *b = &a;
> }
>
> $ gcc -std=iso9899:1999 -pedantic-errors -fhosted -c x.c
> x.c: In function 'test_exact':
> x.c:5: error: pointer targets in initialization differ in signedness
>
> The 255 constant has the u suffix on it like it should and uint8_t
> is defined as 'unsigned char' like it should be but I still get an error.
> Why? Is there some type promotion going on under the covers?
Yes, unsigned types narrower than int are promoted to signed int in
arithmetic, and C99 (plus TCs - this was unclear in the original standard)
requires the macros for constants and limits to use the promoted types.
Thus UINT8_MAX should have type int, and UINT8_C should generate a
constant of type int. Headers doing otherwise should be fixed upstream
and with fixincludes.
--
Joseph S. Myers
joseph@codesourcery.com