This is the mail archive of the gcc-bugs@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]

Re: Broken enum arithmetic in C


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~

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