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: G++ enums 'underlying type'


> From: Gabriel Dos Reis <gdr@integrable-solutions.net>
> Paul Schlie <schlie@comcast.net> writes:
> 
> | No one asked about enumerators.
> 
> so what are you answering to in
> 
>   http://gcc.gnu.org/ml/gcc/2004-12/msg01174.html
> 
> with your
> 
>    Converted to integer type of compatible rank, not "int"
> 
> ?
> 
> -- Gaby

Within the context of your initial response:

| > In C, enumerator are ints -- even though the associated enumeration
| > type is considered a distinct types.  Only C++ allows for the smallest
| > integer type as the underlying type; and C++ enumerators are not ints.

To which I responded:

>    Converted to integer type of compatible rank, not "int"

To which, you correctly observed:

| > You're confusing an "enumerated type" ("enumeration" in C++ speak)
| > with "enumerator", i.e. the named constants.

As I was responding based on my understanding of C enum's (not enumerators).

[ as an aside, it would seem that an enumerator's type size within an enum
declaration is largely irrelevant, as enumerators aren't instantiated by
a declaration, they're just parsed; as they define the enum's range and the
symbolic associations of values within that range; which when instantiated
may be converted to any integer type size if and when required for proper
expression evaluation. Where when if enumerators constants are symbolically
appear as symbolic constants in run-time expressions, they need not be
represented as being any larger than the smallest type-size capable of
representing it's value, regardless of the size of it's corresponding
enumeration, as small constants may always be promoted if/when required
for comparison or assignment upon demand, but need not prior.

I realize this subtleties make little difference on most large target
machines, but are significant on smaller machines where the chosen int
size may correspond to several word-wide machine operations; but note
that in most cases GCC's often needless premature promotion of smaller
than int types, enum's, bool, and corresponding constants, tend to inhibit
efficient expression representation and corresponding code generation on
small targets, not the C standard it's self; keeping declared variables and
operations sized as optimally small as possible enable the most efficient
expression representation possible on small targets, with no loss of
efficiency to large targets (and occasionally even some improvements),
while the converse is not true. Which is why I tend to tend to stress
it's importance when it can be compliantly implemented (and need not
literally follow the prescribed method if known to yield equivalent
results), although I acknowledge my emphasis is occasionally misplaced,
I apologize. ]



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