Path: utzoo!mnetor!uunet!husc6!mailrus!tut.cis.ohio-state.edu!osu-cis!att-cb!clyde!watmath!rbutterworth From: rbutterworth@watmath.waterloo.edu (Ray Butterworth) Newsgroups: comp.lang.c Subject: Re: { enumeration-list , } Message-ID: <17671@watmath.waterloo.edu> Date: 21 Mar 88 13:58:20 GMT References: <660@kuling.UUCP> <25526@cca.CCA.COM> <680@kuling.UUCP> Organization: U of Waterloo, Ontario Lines: 29 In article <680@kuling.UUCP>, martin@kuling.UUCP (Erik Martin) writes: > Then, why isn't an 'optional' comma allowed after the last constant in an > enumeration list? I bumbed into this fact when I needed to generate both > an initialized array and an enumeration declaration from a file of symbols, > and found that I had to give special treatment to the last item in the > enumeration. *Very* frustrating. Yes, it's frustrating and inconsistent. However, when I make an enumeration list, I tend to give the last one a special name. e.g. typedef enum { COL_RED, COL_GREEN, ... , COL_PINK, COL_DIMENSION } Colour; The ?_DIMENSION name is always last, for all the enumeration types, and it never has a comma after it. The ?_DIMENSION is handy if one wants to allocate an array, e.g. auto Table *table = (Table *)malloc(COL_DIMENSION*sizeof(Table)); or auto Table table[COL_DIMENSION]; auto int index = (int)COL_DIMENSION; while (--index >= 0) { blah blah table[index] blah blah; } or if you suspect that someone gave you a bad function argument, if ((unsigned int)arg >= (unsigned int)COL_DIMENSION) oops();