Search code examples
cdata-structuresincomplete-type

c - Error: "incomplete type is not allowed" , IAR compiler


Please advise, what's wrong?

in .h

struct {
      uint8_t time;
      uint8_t type;
      uint8_t phase;
      uint8_t status;
} Raw_data_struct;  


typedef struct Raw_data_struct Getst_struct;

void Getst_resp(Getst_struct Data);

in .c

void Getst_resp(Getst_struct  Data) //Here Error: incomplete type is not allowed                                        
{

};

Solution

  • The error is due to the mixture when declaring the 'struct Raw_data_struct'. You can have a look of the post typedef struct vs struct definitions [duplicate].

    To declare your struct, you have to use:

    struct Raw_data_struct {
      uint8_t time;
      uint8_t type;
      uint8_t phase;
      uint8_t status;
    };
    

    Instead of :

    struct {
      uint8_t time;
      uint8_t type;
      uint8_t phase;
      uint8_t status;
    } Raw_data_struct;
    

    If you want to declare both the struct and the typedef, you have to use:

    typedef struct Raw_data_struct {
      uint8_t time;
      uint8_t type;
      uint8_t phase;
      uint8_t status;
    } Getst_struct;