Number of enums
Norman Diamond
diamond at jit345.swstokyo.dec.com
Mon Jan 21 19:36:57 AEST 1991
In article <703 at caslon.cs.arizona.edu> dave at 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_ ## <enum type name> */
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 at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
More information about the Comp.lang.c
mailing list