are enums integers in ANSI?

T. William Wells bill at twwells.uucp
Sun Nov 27 21:02:03 AEST 1988


In article <8457 at alice.UUCP> dmr at alice.UUCP writes:
: Here is a more subtle example.
:
:       int x;
:       enum e x;
:
: A compiler is permitted to accept this if, for example, it decides
: that the integral type all enums are compatible with is int.

That bothers me. I thought the purpose of the compatible/composite
stuff was to permit merging the types of arrays and functions.  It
seems a mistake to permit other than that. Are there reasons why this
is permitted? Or is this accidental?

: It is permitted to reject it also; in fact it may reject it even
: if you try all the possibilities of char, unsigned, long, etc. instead
: of int.  The reasoning (theoretically) is that the compiler doesn't
: have to announce in advance just which variety of int is compatible
: with a particular enum.  In effect, it is allowed to play the hostile
: adversary, and choose a compatible integral type for this enum other than
: the one you guessed!

But it does!  The standard says that which one it is compatible with
is "implementation defined". That implies that it has to be
documented.

Furthermore, if we accept that the notion, stated in the Rationale,
that "implementation defined" does not extend to failing to translate
the program, applies here, then there has to be at least *one*
declaration that will work.

---
Bill
{uunet|novavax}!proxftl!twwells!bill



More information about the Comp.std.c mailing list