gcc compiler bug: unsigned enum types

Thomas R. Truscott trt@cs.duke.edu
Mon Sep 11 12:26:00 GMT 2000


> GCC complies with the current version of the standard in this respect.

Yes, but GCC complies differently from most other compilers,
and this causes problems with code that uses enums incorrectly.
(A typical situation is enum {red, white, blue} color;
and then someone uses -1 as a "none of the above" indication.)

The doc for gcc claims that "-fshort-enums" is not the default
for compatibility with other compilers, but I suspect the practical
reason is for compatibility with the numerous programs
that assume "int" and "enum" are interchangeable.
(I was unable to reach stage2 of gcc build with -fshort-enums, 
but perhaps that was just me and I shouldn't even mention it...)

Anyway, if gcc wants to be "compatible with other compilers"
then it should make enums signed by default.

Almost as useful, and more interesting, would be "bounded enums"
with run-time checks of assignments to (and fetches from)
enums to ensure that the value is in the legal range.

Tom Truscott


More information about the Gcc-bugs mailing list