CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

enum compile error "Expecting an Identifier"

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MMurray



Joined: 19 Feb 2011
Posts: 22

View user's profile Send private message

enum compile error "Expecting an Identifier"
PostPosted: Sun Mar 10, 2013 6:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 10, 2013 8:28 am     Reply with quote

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: 19352

View user's profile Send private message

PostPosted: Sun Mar 10, 2013 9:03 am     Reply with quote

"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

View user's profile Send private message

enum compile error "Expecting an Identifier"
PostPosted: Sun Mar 10, 2013 1:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 10, 2013 1:57 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Sun Mar 10, 2013 2:08 pm     Reply with quote

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

View user's profile Send private message

enum compile error "Expecting an Identifier"
PostPosted: Sun Mar 10, 2013 2:11 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group