question about an array of enum

Paul D. Smith pds at lemming.webo.dg.com
Wed Nov 7 02:07:19 AEST 1990


[] I don't think a compiler can make enums smaller than int and be
[] ANSI compliant, since the standard says that enums are ints.

K&R II: Section A8.4, p. 215:
    "The identifiers in an enumerator list are declared as constants
     of type `int' ... "

(sorry, I don't have a copy of ANSI ... )

[] Further, enums don't except the short/long keywords (at least not
[] on MSC and HP-UX C).  It is for this reason that I almost never use
[] enums.  Their size varies from machine to machine and there is
[] nothing you can do about it.

If you *care* about how many bits are in the physical representation
of an enum, then you shouldn't be using one.  enum's are newfangled
(:-) software engineering / data abstraction concepts; their purpose
is to represent the type of a variable with a predefined, distinct set
of possible values (presumably a smaller set than those representable
by an `int'! :-).

I admit that I use the actual values of enums sometimes, but I've
never had a reason to use a value larger than the size of even a
16-bit integer -- mostly I use them as array indicies when I use the
actual value, since my debugger is quite intelligent about enums and
handily prints their symbolic value.  When I'm not using the actual
value I never bother to set it, just to show I don't care.
--

                                                                paul
-----
 ------------------------------------------------------------------
| Paul D. Smith                          | pds at lemming.webo.dg.com |
| Data General Corp.                     |                         |
| Network Services Development           |   "Pretty Damn S..."    |
| Open Network Applications Department   |                         |
 ------------------------------------------------------------------



More information about the Comp.lang.c mailing list