Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!gaynor From: gaynor@paul.rutgers.edu (Silver) Newsgroups: comp.lang.c Subject: Re: enum style Keywords: enum type enumerated style Message-ID: Date: 27 May 91 21:01:39 GMT References: <1991May27.175350.26033@aio.jsc.nasa.gov> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 28 bill@gothamcity.jsc.nasa.gov (Bill Shirley) writes: > [Opinions on the overall style of the following enum example? > I'm mostly concerned with readability/maintainability/portability.] > > typedef enum { NoState, > STATE_A, STATE_B, STATE_C, /* ... */ > NUM_STATES } State; There are some drain-bamaged compilers out there that don't by default map the first element to 0. I recommend explicitly mapping the first element to the desired integer, and, to avoid name clashes, prefix each of the elements with the name of the type. Mine tend to look like this: typedef enum {thing_min = 0, thing_0 = thing_min, thing_1, thing_2, ..., thing_N, thing_max = thing_N, thing_lim} thing; > NUM_STATES will be the correct value always? Should be, unless you veer from the default ordering. In your example, it should have the value 4; in mine, N+1. Regards, [Ag]