#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    C Compiler errors


    Hi Guys,
    I mainly write C programs for embedded applications, a few months back with some help from you I wrote a Usart communications program for the NXP LPC1443 that worked quite well.
    I am now working with a new uProcessor and using a different IDE/compiler and when porting the program I am getting some errors that I did not get before. I tried to look at the issues but can not understand the errors that the compiler is throwing at me, Hence I need your help. I am sure this is because I am missing some C knowledge so please fell free to send me some links related to the subject.

    Here is the header file that is giving me the errors:

    Code:
    /* Define to prevent recursive inclusion -------------------------------------*/
    #ifndef __BUFFERSTORE_H
    #define __BUFFERSTORE_H
    
    #define	NUMBEROFBUFFERS	20	
    
    /*MultiBuffer Definition
     * This is the work horse of this program. it defines
     * storage for either data for processing, packet for
     * transmission or just received and also the raw data for
     * physical medium
     * These definition by using the union construct will allow
     * for easier data manipulation.
     */
    
    typedef volatile union
    {
    	struct
    	{
    		/*	For data storage can be used for everything (TX or RX)	*/
    		char processNumber;	/*	will probably id the task that needs the data	*/
    		//char pNumberB;		/*	Packet number binary (one byte)	*/
    		char dataSize;		/*	number of bytes(max 10)	*/
    		char data[10];		/*	Data bytes	*/
    
    	}dataS;	/*	Data structure	*/
    
    	struct
    	{
    		/*	For Packet Storage can be used for RX or TX
    			All values have been translated to Hex ASCII
    			Hence the need for Two bytes in most cases.	*/
    		char pStartChar;	//Start char normally (
    		char pTypeChar;		//Packet Type 1 to F
    		char pNumberH[2];	//packet number in Hex 00 to FF
    		char pDSize[2];		//packet size in Hex 
    		char pChecksum[2];	//packet checksum
    		char pData[20];		//packet Data
    		char pEndChar;		//End char normally )
    		char pSize;
    	}packetS;	// Packet structure
    	
    	struct
    	{
    		//for Packet Storage after Hex Ascii to binary conversion
    		// may not be needed can be used for RX or TX
    		//All values have been translated to Binary values
    		char pStartChar;	//Start char normally (
    		char pTypeChar;		//Packet Type 1 to F
    		char pNumber;		//packet number in Hex 00 to 255
    		char pDSize;		//packet size 
    		char pChecksum;		//packet checksum 00 to FF
    		char pData[10];		//packet Data
    		char pEndChar;		//End char normally )
    		
    	//for raw hex data
    	char rBuffer[30]; // this buffer is defined for ease of use by the UART
    }MultiBuffer;
    
    /* --------------------------------------------------------------------------- */
    
    
    /* Queue Handling */
    
    /*	The Element as two parts, the payload or data part
    	and a pointer to the next Element, hence it can be used to
    	implement a linked list. 									*/
    
    typedef	volatile struct Element Element;	/*	This is required to let the compiler know
    												that the struct Element is te same as the Element
    												or it will generate an "incomplete" definition error. */
    
    struct Element
    {
    	MultiBuffer *payload;
    	volatile struct Element *nextElement;
    };
    
    
    /*	To implement a queue de only thing you need really is to know where the Head of 
    	the Queue and its tail is. By then accessing the elements they will let you know 
    	where the others are.																*/
    volatile typedef struct
    		{
    			volatile Element *head;
    			volatile Element *tail;
    		}Queue;
    
    /* ------------------------------------------------------------------------------------*/
    
    
    volatile Queue *createQueue(void);
    void createQueues(void);
    volatile Queue *addElementToQueue(volatile Queue *queue, volatile MultiBuffer *bufferPrt);
    volatile MultiBuffer *getElementFromQueue(volatile Queue *queue);
    		
    		
    #endif /* __BUFFERSTORE_H */

    On this line...

    Code:
    /*	The Element as two parts, the payload or data part 	and a pointer to the next Element, hence it can be used to 	implement a linked list. 									*/  typedef	volatile struct Element Element;	/*	This is required to let the compiler know 												that the struct Element is the same as the Element 												or it will generate an "incomplete" definition error. */
    I get errors:
    .\inc\bufferStore.h(98): error: #70: incomplete type is not allowed

    and

    .\inc\bufferStore.h(98): error: #80: a storage class may not be specified here


    On this part of the code:

    Code:
    struct Element 
    { 	MultiBuffer *payload;
     	volatile struct     Element *nextElement; 
    };
    I get erros:

    .\inc\bufferStore.h(104): error: #20: identifier "MultiBuffer" is undefined

    and

    .\inc\bufferStore.h(106): warning: #40-D: expected an identifier

    The other errors are similar, if can find out what the problem is I can fix the rest.

    Thank you in advance for any help.

    Best Regards
    Luis
    Last edited by lasm; December 3rd, 2012 at 03:19 AM. Reason: Code Tags getting all the text inline.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,387
    Rep Power
    1871
    > }MultiBuffer;
    Well the first problem seems to be that you're missing a closing brace around about here.

    Next, cut down on the happy stick with the word 'volatile' written on it.
    It makes no sense for example to declare a typedef as being volatile.

    This compiles with gcc.
    Code:
    #define NUMBEROFBUFFERS 20  
    
    /*MultiBuffer Definition
     * This is the work horse of this program. it defines
     * storage for either data for processing, packet for
     * transmission or just received and also the raw data for
     * physical medium
     * These definition by using the union construct will allow
     * for easier data manipulation.
     */
    
    typedef /*volatile*/ union
    {
      struct
      {
        /*  For data storage can be used for everything (TX or RX)  */
        char processNumber; /*  will probably id the task that needs the data */
        //char pNumberB;    /*  Packet number binary (one byte) */
        char dataSize;    /*  number of bytes(max 10) */
        char data[10];    /*  Data bytes  */
    
      }dataS; /*  Data structure  */
    
      struct
      {
        /*  For Packet Storage can be used for RX or TX
          All values have been translated to Hex ASCII
          Hence the need for Two bytes in most cases. */
        char pStartChar;  //Start char normally (
        char pTypeChar;   //Packet Type 1 to F
        char pNumberH[2]; //packet number in Hex 00 to FF
        char pDSize[2];   //packet size in Hex 
        char pChecksum[2];  //packet checksum
        char pData[20];   //packet Data
        char pEndChar;    //End char normally )
        char pSize;
      }packetS; // Packet structure
      
      struct
      {
        //for Packet Storage after Hex Ascii to binary conversion
        // may not be needed can be used for RX or TX
        //All values have been translated to Binary values
        char pStartChar;  //Start char normally (
        char pTypeChar;   //Packet Type 1 to F
        char pNumber;   //packet number in Hex 00 to 255
        char pDSize;    //packet size 
        char pChecksum;   //packet checksum 00 to FF
        char pData[10];   //packet Data
        char pEndChar;    //End char normally )
        
        //for raw hex data
        char rBuffer[30]; // this buffer is defined for ease of use by the UART
      } foo;  //!! pick a name for this nested struct
    }MultiBuffer;
    
    /* --------------------------------------------------------------------------- */
    
    
    /* Queue Handling */
    
    /*  The Element as two parts, the payload or data part
      and a pointer to the next Element, hence it can be used to
      implement a linked list.                  */
    
    #if 0
    //!! serves no purpose.
    //!! you probably added this to 'fix' the missing earlier brace.
    typedef volatile struct Element Element;  /*  This is required to let the compiler know
                            that the struct Element is te same as the Element
                            or it will generate an "incomplete" definition error. */
    #endif
    
    struct Element
    {
      MultiBuffer *payload;
      volatile struct Element *nextElement;
    };
    
    
    /*  To implement a queue de only thing you need really is to know where the Head of 
      the Queue and its tail is. By then accessing the elements they will let you know 
      where the others are.                               */
    /*volatile*/ typedef struct
        {
          //!! you need struct Element here, because Element isn't typedef'ed
          volatile struct Element *head;
          volatile struct Element *tail;
        }Queue;
    
    /* ------------------------------------------------------------------------------------*/
    
    
    volatile Queue *createQueue(void);
    void createQueues(void);
    volatile Queue *addElementToQueue(volatile Queue *queue, volatile MultiBuffer *bufferPrt);
    volatile MultiBuffer *getElementFromQueue(volatile Queue *queue);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo