'C' enum syntax problem

Daniel Elbaum dan at oresoft.uu.net
Wed Apr 26 03:42:15 AEST 1989


In article <1095 at cvbnet2.UUCP> krishna at xenon.uucp (Temporary) writes:
>I seem to have some problem in using the enum construct on Sun-3
>The following declarations generate an error.
>
>   typedef enum WEEK { MONDAY, TUESDAY, SATURDAY, SUNDAY };
>   typedef enum WEEK_END { SATURDAY, SUNDAY };
>

The identifiers of the enum are, in effect, integral constants.
You can use MONDAY, TUESDAY, etc. as though they were manifest
constants, assign them to int's (casting may be necessary), and
just generally go wild.  Because of this, the names of the
constants may not be reused in the same scope.  You might try
something like this:

enum WEEK { MONDAY, TUESDAY, SATURDAY, SUNDAY };
enum WEEK_END { Saturday = SATURDAY, Sunday = SUNDAY };

unless, of course, your implementation of C is case-insensitive.

-- 
Not responsible                :  uunet     -
for this posting               :  tektronix   \!oresoft!dan
                               :  reed        /         dan at oresoft.uu.net
                               :  sun!nosun -



More information about the Comp.lang.c mailing list