This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: underlying type for enums


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]