Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ncar!noao!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: Number of enums Message-ID: <726@caslon.cs.arizona.edu> Date: 24 Jan 91 14:32:22 GMT References: <703@caslon.cs.arizona.edu> <1991Jan21.133917.18458@cbnews.att.com> <708@caslon.cs.arizona.edu> <279DC67C.6ABD@tct.uucp> Organization: U of Arizona CS Dept, Tucson Lines: 46 In article <279DC67C.6ABD@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes: >According to dave@cs.arizona.edu (Dave P. Schaumann): >>[suggests the new operator 'numberof' would be A Good Thing] > >Hardly. Given: > > typedef enum { > CORGE = -100, QUUX = -50, > LARRY = 1, MOE = 2, CURLY = 4, JOE = 9, > EX_PARROT = 32767 > } PLUGH; > >Of what use would numberof(PLUGH) be? Indeed. What use would it be? I intended that the numberof operator would be useful for non-initialized enums only. If the programmer used the numberof operator on PLUGH, the result shouldn't necessarily be useful. Let me give a more precise definition of what I think 'numberof' should do, to put to rest some questions I have been getting. DEFINE numberof(enum typename) to return the value of the last name in typename incremented by 1. This would be a compile-time operator like 'sizeof'. Thus, the operaton is well-defined over all possible enum definitions, and gives a useful value for default-valued enums. Frankly, I don't really care what happens in the case of an initialized-enum type. The only thing that I would really want is for it to be well defined, and easy to implement. Probably the most serious objection I recieved to this operator was "does C really need another operator?" The only defense I can offer for having numberof() instead of using a special final enum name is that the enum is syntactically and (IMO) conceptually cleaner. It is true that it offers no new functionality to the language, but I would argue that it is easier to understand "int a[numberof(enum foo)]" at a glance than it is to understand "int b[NUMBER_OF_FOO]". In the first case, all you need to understand is the operation of 'numberof'. In the second case, you also to understand the programmer's style and naming conventions. >Chip Salzenberg at Teltronics/TCT , Dave Schaumann | And then -- what then? Then, future... dave@cs.arizona.edu | -Weather Report