GCC Structure Wacko

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
3 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

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;
    }
}
 

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 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.

0 Likes
SuMa_296631
Level 5
Level 5
50 replies posted 25 replies posted 10 replies posted

 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

0 Likes