Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!think!ima!haddock!karl From: karl@haddock Newsgroups: net.lang.c Subject: Re: enum function bug? Message-ID: <86900054@haddock> Date: Tue, 16-Sep-86 19:03:00 EDT Article-I.D.: haddock.86900054 Posted: Tue Sep 16 19:03:00 1986 Date-Received: Wed, 17-Sep-86 06:16:20 EDT References: <299@sdchema.sdchem.UUCP> Lines: 37 Nf-ID: #R:sdchema.sdchem.UUCP:299:haddock:86900054:000:1950 Nf-From: haddock!karl Sep 16 19:03:00 1986 sdchem!tps (Tom Stockfisch) writes: >I want to pass a pointer to function returning [enum bool] to a function, >but lint says I'm not doing it right. Cc and lint disagree about what "enum" really means. Lint calls it a new datatype, but cc thinks it's just a synonym for "int" in some contexts. Apparently the distinction is lost somewhere between lint pass 1 and pass 2. Yes, it's a bug. #if SOAPBOX I think cc should also treat them as distinct types. (The easy-going days of "everything is an int" are over, folks. Egad, now you have to *declare* functions, even if you're just passing the result to another function!) If you need an int context, you should cast the enum into an int. (Though switch(enum) should still work, provided all the case labels are enums.) I suppose an enum actually specifies an *ordered* set, so "++" and "--" are acceptable, as well as "+" and "-", but they work as with pointers: enum+int == enum, enum-enum == int. This proposal would make your "enum bool" less useful, but "typedef int bool" (which is what I always use) is just as good anyway. The only addition I'd like to make is to allow one to declare an array to be subscripted by an enum: "double foo[enum color]; foo[RED] = 1.0; ...". Such an array would *not* be subscriptable by int (though of course an integral expression could be cast into enum color and then used as a subscript). This would often obviate the need for a constant NCOLORS, and make the code more palatable to both cc and lint. A smart compiler could make a special case for sparse enums (enum color { RED=0, BLUE=100 }), as long as it's guaranteed that each valid instance of the enum type may be used as a subscript. The idea could be extended to allow any datatype, e.g. "int foo[char]" (which would subscript from -128 to 127 on a pdp11 or vax), but this is less useful. #endif /* SOAPBOX */ Karl W. Z. Heuer (ima!haddock!karl; karl@haddock.isc.com), The Walking Lint