This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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: c99 stdint.h question


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


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