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 CCS Technical Support

typedef enum

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







typedef enum
PostPosted: Tue Jul 22, 2008 3:53 pm     Reply with quote

If I have the following:

typedef enum{
A,
B,
C
} ALGORITHM_STATE;

How do I declare the variable “state” of the above typedef in the main program?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 22, 2008 6:01 pm     Reply with quote

The answer, as always, is to make a test program. Probably you have
some idea of how to do it. Make a test program and see if your idea is
correct. Example:
Code:

#include <16F877.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

typedef enum{
A,
B,
C
}ALGORITHM_STATE;

//=================================
void main()
{
ALGORITHM_STATE state;

state = A;
printf("%u ", state);

state = B;
printf("%u ", state);

state = C;
printf("%u ", state);

while(1);
}


Here's the output when run in MPLAB simulator:
Quote:
0 1 2
jman
Guest







typedef enum
PostPosted: Wed Jul 23, 2008 7:34 am     Reply with quote

I tried to declare "state" using the following:

ALGORITHM_STATE state;

Then, I coded:

state = A;

When I compiled, I got an error. The IDE tells me it expects a variable in the line where I declare "state."
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Jul 23, 2008 1:13 pm     Reply with quote

did you run PCM Programmer's test program at all?
Does it work for you?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 23, 2008 1:31 pm     Reply with quote

And also, post your compiler version.
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