'C' enum syntax problem
Guy Harris
guy at auspex.auspex.com
Wed Apr 26 04:23:11 AEST 1989
>Does it mean that subsets of an enum cannot be defined ?
It means that the names of enumeration members are global, not local to
the "enum" in which they're used; this means that you can't have the
same "enum" name belong to two different enumerations (at least not with
different values) within the same scope.
Since C has no notion of a subrange type, and since you seem to be
trying to create a subrange type of WEEK, the answer is basically "no,
subranges of an enum cannot be defined."
>Is this a bug in my C Compiler ?
No. It is doing the correct thing.
>What does PAns say about this ?
3.5.2.2 Enumeration specifiers
...
Semantics
The identifiers in an enumerator list are declared as
constants that have type "int" and may apper wherever such are
58
permitted.
...
58. Thus, the identifiers of enumeration constants declared in
the same scope shall all be distinct from each other and
from other identifiers declared in ordinary declarators.
>Is there a work around ?
typedef enum WEEK {
WEEK_MONDAY, WEEK_TUESDAY, WEEK_WEDNESDAY,
WEEK_THURSDAY, WEEK_FRIDAY,
WEEK_SATURDAY, WEEK_SUNDAY
};
typedef enum WEEK_END {
WEEK_END_SATURDAY, WEEK_END_SUNDAY
};
is one possibility.
More information about the Comp.lang.c
mailing list