Broken enum arithmetic in C

Richard Henderson rth@cygnus.com
Sun Apr 30 12:03:00 GMT 2000


On Sun, Apr 30, 2000 at 02:48:16PM +0200, Peter Osterlund wrote:
> Consider this C code:
> 
> 	enum { v = 1 };
> 	signed char f()
> 	{
> 	    return -v;
> 	}
> 
> On i686-pc-linux-gnu, compiling this code with recent snapshots
> generats a bogus warning:
> 
> 	bug.c: In function `f':
> 	bug.c:4: warning: overflow in implicit constant conversion

This is not a bug.  GCC chooses to make non-signed enumerations
unsigned.  Thus `v' is effectively `1U'. 

The relevant standards leave the choice of whether to use signed
or unsigned backing types (in the absense of negative values in
the enumerator) up to the implementation.


r~


More information about the Gcc-bugs mailing list