Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!shlump.nac.dec.com!tkou02.enet.dec.com!jit345!diamond From: diamond@jit345.swstokyo.dec.com (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: Number of enums Message-ID: <1991Jan21.083657.7378@tkou02.enet.dec.com> Date: 21 Jan 91 08:36:57 GMT References: <703@caslon.cs.arizona.edu> Sender: news@tkou02.enet.dec.com (USENET News System) Reply-To: diamond@jit345.enet@tkou02.enet.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 25 In article <703@caslon.cs.arizona.edu> dave@cs.arizona.edu (Dave P. Schaumann) writes: >C is lacking (as far as I know) a general way to get the last value of an >enum type. Yes. >For instance, suppose I have: >typedef enum { SUN, MON, TUE, WED, THU, FRI, SAT } days_t ; >The best I have come up with is to do this: >#define last_days_t SAT /* Named as last_ ## */ I use: typedef enum days_t { SUN, MON, TUE, WED, THU, FRI, SAT, NO_OF_DAYS } days_t; And make sure that new days are added before NO_OF_DAYS. If I also need LAST_DAY, I use: #define LAST_DAY (NO_OF_DAYS - 1) I wouldn't make a name like "last_days_t" a constant; the name looks like a type. Of course, every type name that I named during the past 11 years is now in the POSIX reserved name space :-( -- Norman Diamond diamond@tkov50.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it.