Grouse: What's the point of enum?
mark.e.smith
marks at cbnewsl.att.com
Mon Apr 22 13:36:54 AEST 1991
In article <678 at taumet.com> steve at taumet.com (Stephen Clamage) writes:
>ts at cup.portal.com (Tim W Smith) writes:
>
>>Anyway, the real point is to allow lower case names for constants. If
>>you try this in a header file...
>
I love it. Score one for the anti-style guide side.
>
>Preprocessor defines have no scope. They reach into the internals of
>structs and functions and can result in mystifying error messages and
>hard-to-find bugs. The enumeration names are scoped, and can be made
>local to functions if desired, and can be locally overridden inside
>functions which don't know and don't want to know about a #define (or
>enum) buried inside some nested include file.
Yes. The answer hints at the model, which is that an enum defines a type,
i.e. a set of values. Defining types is a Good Thing. Otherwise, there's
nothing in the program syntax which hints at the relationship among the values.
Compare for example the three styles:
#define APPLE 1
#define ORANGE 2
vs.
#define APPLE 1
#define ORANGE ( APPLE + 1 )
which is better, since at least we have some clue that an apple and an
orange are somehow related; vs.
enum { APPLE = 1, ORANGE } ;
which is explicit.
Mark Smith
More information about the Comp.lang.c
mailing list