View previous topic :: View next topic |
Author |
Message |
MMurray
Joined: 19 Feb 2011 Posts: 22
|
enum compile error "Expecting an Identifier" |
Posted: Sun Mar 10, 2013 6:42 am |
|
|
I am adding an enum to working code and the compiler is pushing back with errors. Here is my enum declaration, I am using a PIC16F877.
Code: | void display(void);
enum colors {off,red,grn}color;
U8 i=0;
U16 tick=0;
U8 old_TMR0=0;
u8 flash=0;
|
Thanks. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Mar 10, 2013 8:28 am |
|
|
Always post your compiler version number and preferably a compilable program.
Your program is incomplete so we can't reproduce your problem. The enum declaration looks fine.
I tested in v4.141: Code: | #include <16F877.h>
#fuses HS, NOWDT, NOLVP, PUT
#use delay(clock=10MHz)
enum colors {OFF, RED, GREEN} color;
enum colors my_color = RED;
void main()
{
color = OFF;
} | Please not how I wrote the enum names in full capital letters. Enums are like constants and your code is easier to read when all constants look different from variable names. The compiler doesn't care about notation but for humans it makes things a lot easier when keep to some simple coding styles. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Sun Mar 10, 2013 9:03 am |
|
|
"Expecting an identifier", probably implies one of the names being used is already 'in use' somewhere as possibly a function declaration.
Best Wishes |
|
|
MMurray
Joined: 19 Feb 2011 Posts: 22
|
enum compile error "Expecting an Identifier" |
Posted: Sun Mar 10, 2013 1:47 pm |
|
|
I am using the same compiler, 4.141.
There are no other instances of color or of colors. Just to be sure I changed the name of the enum type to mattmurray.
enum mattmurray {OFF, RED, GREEN} matt;
Same compile error.
I ran your code sample and it compiled just fine.
I then took that code and pasted it into the original, and the same compile error. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Mar 10, 2013 1:57 pm |
|
|
CCS error messages are not always correct. Often you have to look immediately above the indicated line to find the real problem.
Without seeing more of your code we can't say where the problem is. What you can do is to cut parts from your program and trying to compile again. Repeat the process until the program compiles again, then you know the problem is in the last part you removed. If you still don't see the problem then try to remove even more code. In the end you will have a program of about 10 lines. If you still don't see the problem you can post that small program and we will have a look. |
|
|
nurquhar
Joined: 05 Aug 2006 Posts: 149 Location: Redditch, UK
|
|
Posted: Sun Mar 10, 2013 2:08 pm |
|
|
It might be worth trying with different value names as well incase of conflicts. It could be OFF is a popular value defined somewhere else. eg.
Code: | enum colors {__OFF, __RED, __GREEN} color;
|
|
|
|
MMurray
Joined: 19 Feb 2011 Posts: 22
|
enum compile error "Expecting an Identifier" |
Posted: Sun Mar 10, 2013 2:11 pm |
|
|
Ok, I feel bad, color or colors were not anywhere else in the code but RED was. That was it, name already in use.
Thanks for the help. |
|
|
|