This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: underlying type for enums
- From: "Zack Weinberg" <zack at codesourcery dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: jsm at polyomino dot org dot uk, Jason Merrill <jason at redhat dot com>, gcc at gcc dot gnu dot org
- Date: Tue, 02 Dec 2003 09:31:16 -0800
- Subject: Re: underlying type for enums
- References: <20031202090652.GC32317@redhat.com>
Richard Henderson <rth@redhat.com> writes:
> The C++ standard defines the "underlying type" of an enum as an
> integral type which can hold all of the enumerator values. It then
> goes on to define what all of the possible values are based on the
> set of enumerators present. Namely, the smallest and largest
> values of a bit-field that can store all of the enumerators.
>
> The C standard uses the term "compatible type". In C99 we are
> given free rein to choose any signed or unsigned integer type,
> including extended integer types. I don't have C90 handy to
> check wording there, but since extended integer types did not
> exist I don't think we have the same freedom. Anyway, let me
> ignore C90 for the moment.
I do have C90 handy - it says "Each enumerated type shall be
compatible with an integer type; the choice of type is
implementation-defined [but shall be capable of representing the
values of all members of the enumeration]" (6.5.2.2p4 - text in
brackets added in TC2) C90's integer types are what C99 calls basic
integer types, so I think you're right that we don't have the same
freedom that C99 allows.
But is this the right way to look at it? How do we handle "int foo :8"
and why is it different (apparently) from the way we handle
"enum blah foo :8" ?
zw