enums

Walter Bright bright at Data-IO.COM
Sat Jul 23 04:32:21 AEST 1988


In article <469 at m3.mfci.UUCP> karzes at mfci.UUCP (Tom Karzes) writes:
<If you define an enum with a long list of values, a natural thing to want
<to do is determine the number of values in the enum (sort of like sizeof).
<    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
<and hope that people correctly update this macro every time they add or
<delete a tree.
<Does ANSI C provide a reasonable way to do this?

I use:
	enum tree {oak,elm,maple,birch,willow,cypress,spruce,TREE_COUNT};



More information about the Comp.lang.c mailing list