This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: gcc compiler bug: unsigned enum types
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Re: gcc compiler bug: unsigned enum types
- From: "Thomas R. Truscott" <trt at cs dot duke dot edu>
- Date: Mon, 11 Sep 2000 15:25:58 -0400 (EDT)
> 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