Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.c Subject: Re: enums Message-ID: <24261@think.UUCP> Date: 21 Jul 88 02:23:09 GMT References: <1608@dataio.Data-IO.COM> <469@m3.mfci.UUCP> Sender: usenet@think.UUCP Reply-To: barmar@kulla.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 33 In article <469@m3.mfci.UUCP> karzes@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@think.com {uunet,harvard}!think!barmar