question about an array of enum

Henry Spencer henry at zoo.toronto.edu
Wed Nov 7 11:31:26 AEST 1990


In article <9130019 at hpavla.AVO.HP.COM> gary at hpavla.AVO.HP.COM (Gary Jackoway) writes:
>I don't think a compiler can make enums smaller than int and be ANSI
>compliant, since the standard says that enums are ints...

No it doesn't.  It says that each one is "compatible with an integer
type; the choice of type is implementation-defined" and that the *constants*
must have values that fit in an int.  There is actually no promise, as
nearly as I can tell, that an enumerated type is big enough to hold the
constants it is declared with!  Certainly there is no promise that
anything other than those constants will fit.  So an implementation
could easily decide that `enum { f=0, t=1 }' is represented as `char'
rather than `int'.
-- 
"I don't *want* to be normal!"         | Henry Spencer at U of Toronto Zoology
"Not to worry."                        |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list