gcc compiler bug: unsigned enum types

Geoff Keating geoffk@cygnus.com
Mon Sep 11 07:56:00 GMT 2000

Alan Morgan <arm@thebe.camcon.co.uk> writes:

> The bug is that gcc makes "an enum type be of type unsigned int (or maybe
> unsigned char) rather than signed int as it should be according to K&R 2nd
> edition section A8.4 pages 214-215."

The ISO C standard, in section "enumeration specifiers",
paragraph 4, says

  Each enumerated type shall be compatible with *char*, a signed
  integer type, or an unsigned integer type.  The choice of type is
  implementation-defined, but shall be capable of representing the
  values of all the members of the declaration.

The previous 1989 version of the C standard simply said

  Each enumerated type shall be compatible with an integer type;
  the choice of type is implementation-defined.

which is equivalent, except that an implementation is free to choose a
type that is too small.  GCC complies with the current version of the
standard in this respect.  The K&R books are not necessarily complete
descriptions of the standard.

- Geoffrey Keating <geoffk@cygnus.com>

More information about the Gcc-bugs mailing list