View previous topic :: View next topic |
Author |
Message |
jman Guest
|
typedef enum |
Posted: Tue Jul 22, 2008 3:53 pm |
|
|
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
|
|
Posted: Tue Jul 22, 2008 6:01 pm |
|
|
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:
|
|
|
jman Guest
|
typedef enum |
Posted: Wed Jul 23, 2008 7:34 am |
|
|
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
|
|
Posted: Wed Jul 23, 2008 1:13 pm |
|
|
did you run PCM Programmer's test program at all?
Does it work for you? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 23, 2008 1:31 pm |
|
|
And also, post your compiler version. |
|
|
|