- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So why won't this code compile. Fails on the assign to COM.State
#define BUFSIZE 10
volatile typedef struct {
char Buf[BUFSIZE];
uint8 DataBytes;
uint32 Timer;
uint8 DatainBuf;
uint8 State;
uint8 Timeout;
} comtype;
volatile typedef struct comtype COM;
volatile typedef struct comtype SMS;
int main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
/* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
for(;;)
{
COM.State = 1;
}
}
Ugh, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This one works:
#define BUFSIZE 10
volatile typedef struct {
char Buf[BUFSIZE];
uint8 DataBytes;
uint32 Timer;
uint8 DatainBuf;
uint8 State;
uint8 Timeout;
} comtype;
//volatile typedef struct comtype COM;
comtype COM;
volatile typedef struct comtype SMS;
int main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
/* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
for(;;)
{
COM.State =1;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that works also.
But I still needed to cast the function calls. ie.. Process_Packet( (char * ) COM.Buf);
As a typedef it is easier to use once it has been defined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The 'typedef' does exactly what the name suggests - defines a new data 'type' to the compiler. Once declared it is seen as exactly the same as an 'int' or 'double' etc.. Therefore 'volatile' does not make sense in that context
What you need to do is to declare the variable with the specified type to be 'volatile', not the type itself.
Susan