Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uwm.edu!linac!att!cbnews!cbnewsl!marks From: marks@cbnewsl.att.com (mark.e.smith) Newsgroups: comp.lang.c Subject: Re: Grouse: What's the point of enum? Message-ID: <1991Apr22.033654.4354@cbnewsl.att.com> Date: 22 Apr 91 03:36:54 GMT References: <12236@dog.ee.lbl.gov> <41440@cup.portal.com> <678@taumet.com> Organization: AT&T Bell Laboratories Lines: 39 In article <678@taumet.com> steve@taumet.com (Stephen Clamage) writes: >ts@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