3 Replies Latest reply on Nov 25, 2014 8:06 PM by SuMa_296631

    GCC Structure Wacko

    DaKn_263916

      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.

        • 1. Re: GCC Structure Wacko
          BoTa_264741

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

          • 2. Re: GCC Structure Wacko
            DaHu_285096

             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.

            • 3. Re: GCC Structure Wacko
              SuMa_296631

               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