This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Broken enum arithmetic in C
- To: Peter Osterlund <peter dot osterlund at mailbox dot swipnet dot se>
- Subject: Re: Broken enum arithmetic in C
- From: Richard Henderson <rth at cygnus dot com>
- Date: Sun, 30 Apr 2000 12:03:04 -0700
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <m2og6rah67.fsf@ppro.localdomain>
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~