Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!amara!mcdaniel From: mcdaniel@adi.com (Tim McDaniel) Newsgroups: comp.lang.c Subject: Re: Number of enums Summary: numberof: a 100 kiloton solution to a 1 gram problem Message-ID: Date: 22 Jan 91 19:59:18 GMT References: <703@caslon.cs.arizona.edu> <1991Jan21.133917.18458@cbnews.att.com> <708@caslon.cs.arizona.edu> Sender: news@adi.COM Organization: Applied Dynamics International, Inc.; Ann Arbor, Michigan, USA Lines: 29 In-reply-to: dave@cs.arizona.edu's message of 21 Jan 91 23:51:00 GMT Distribution: My apologies: the following discussion, about numberof(), is not appropriate to comp.lang.c. We don't have alt.cfutures or suchlike. dave@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@adi.com UUCP: {uunet,sharkey}!amara!mcdaniel