enums

Karl Heuer karl at haddock.ISC.COM
Tue Aug 2 03:46:05 AEST 1988


In article <19795 at cornell.UUCP> blandy at cs.cornell.edu (Jim Blandy) writes:
>And how should we write our enum->int converter?  A cast?  [Not enough
>information if we want to allow duplication of enum names]

Actually, I'd rather have enum arithmetic behave somewhat like pointers, in
that enum+int => enum and enum-enum => int.  Then you can convert an enum to
its ordinal via an expression like "ord = RED - ZEROCOLOR;".

This still doesn't solve the problem of duplication of enum names, but that's
related to the sticky issue of anonymous aggregate constants.  Using my
proposed "remote" operator, you would write "remote(enum color, RED)" if RED
alone is ambiguous.  (Personally, I don't think it's worth the effort, but if
"remote" or equivalent is added for other reasons, then it could probably
handle this problem as well.)

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list