cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ Creator & Designer

ETRO_SSN583
Esteemed Contributor

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
Honored Contributor II

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
Contributor II

 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
Contributor II

 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