enums
Barry Margolin
barmar at think.COM
Thu Jul 21 12:23:09 AEST 1988
In article <469 at m3.mfci.UUCP> karzes at mfci.UUCP (Tom Karzes) writes:
> enum tree {
> oak,
> elm,
> maple,
> birch,
> willow,
> cypress,
> spruce
> };
>
>Now I'd like to define TREE_COUNT to be the number of trees. So I have to
>painfully count them, and write:
>
> #define TREE_COUNT 7
How about
enum tree {
oak, elm, maple, birch, willow, cypress, spruce,
TREE_COUNT /* must always be last */
}
? The only problem with this is if you're into strong typing; the
count of trees isn't actually a kind of tree. But since you're
programming in C we can assume that you aren't fanatical about such
things.
Barry Margolin
Thinking Machines Corp.
barmar at think.com
{uunet,harvard}!think!barmar
More information about the Comp.lang.c
mailing list