question about an array of enum

Steve Summit scs at adam.mit.edu
Thu Nov 8 11:08:47 AEST 1990


In article <1990Nov7.003126.23445 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>...each [enum] is "compatible with an integer
>type; the choice of type is implementation-defined"...
>So an implementation could easily decide that `enum { f=0, t=1 }'
>is represented as `char' rather than `int'.

I think this has been discussed before, perhaps on comp.std.c .
(I do hope it hasn't been discussed much, or recently.  I can't
remember the consensus, but it would be particularly embarrassing
for me to ask a frequently-asked question :-) .)  Does the
standard really allow a different choice to be made for different
enumerations?  Henry's word "each" (which also appears in the
standard, section 3.5.2.2) is interesting, and might suggest that
different sizes are legal, but Appendix F.3.9 (which is, to be
sure, not part of the formal Standard) notes as implementation-
defined "the integer type chosen to represent the values of an
enumeration type."

If different enums can have different sizes (which seems like a
useful license to grant the compiler) the documentation would
have to state "the algorithm by which the integral types for
enumerations are chosen," not "the [single] integral type."

                                            Steve Summit
                                            scs at adam.mit.edu



More information about the Comp.lang.c mailing list