Strange Objective-C/C `enum` behavior
I have this strange issue:
When I create a开发者_如何学Pythonn enum
like this:
typedef enum {
kParcelStatusInTransit,
kParcelStatusArrived,
kParcelStatusDelivered,
kParcelStatusUnknown
} ParcelStatus;
I get an error: expected identifier before numeric constant
When I add even the smallest change to the members name, I get no error:
typedef enum {
kChangeParcelStatusInTransit,
kChangeParcelStatusArrived,
kChangeParcelStatusDelivered,
kChangeParcelStatusUnknown
} ParcelStatus;
How is this possible? What numeric constant is the error talking about? It makes no sense to me...
One of the constants has been #define
d in another file. Because of this, the preprocessor replaces the identifier in the enum
with its value. The compiler then sees this constant value and complains, since it expected an identifier.
Chances are that one of the named constants you're trying to define is already defined in another header, possibly in one of Apple's frameworks. You'll simply need to pick a different name for your constants.
It sounds like you are defining the enum more than once, either literally or by including the file incorrectly.
In addition I can say, compiling Your file with -E option and locating Your error code in a result file will help You to see what happened. F.e.: cc -E myfile.c | grep -B 6 ParcelStatus
精彩评论