Number of enums
Tim McDaniel
mcdaniel at adi.com
Wed Jan 23 06:59:18 AEST 1991
My apologies: the following discussion, about numberof(), is not
appropriate to comp.lang.c. We don't have alt.cfutures or suchlike.
dave at cs.arizona.edu (Dave P. Schaumann) writes:
Of course, the optimal solution would be for ANSI to adopt a 'numberof'
with functionality similar to 'sizeof', so that you could say
numberof(ThingList) to get the number of values.
While this construct may be useful in certain cases, I must point out
that enum constants are not required to be consecutive. There are
often good reasons for avoiding such. There is existing code that
depends on it.
Therefore, there must be a comment at the site of the enum declaration
ANYWAY, warning the next editor that the enum constants must remain
consecutive from zero. If the comment is ignored, the code will
break. In such cases, you might as well add the line
, maxDays /* used for subscript bounds, etc. */
and then there's no need for "numberof()".
(Although it hasn't been suggested yet, I think that adding
"consecutiveenum" and "numberof" would be gross overkill. I believe
that, if the problem can be solved with a comment and reasonable
convention in just one place, there's no need for a larger solution.)
--
Tim McDaniel Applied Dynamics Int'l.; Ann Arbor, Michigan, USA
Work phone: +1 313 973 1300 Home phone: +1 313 677 4386
Internet: mcdaniel at adi.com UUCP: {uunet,sharkey}!amara!mcdaniel
More information about the Comp.lang.c
mailing list