【问题标题】:c - Error: "incomplete type is not allowed" , IAR compilerc - 错误:“不允许不完整的类型”,IAR 编译器
【发布时间】:2017-03-05 04:58:56
【问题描述】:

请指教,怎么了?

.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);

.c

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

};

【问题讨论】:

    标签: c data-structures incomplete-type


    【解决方案1】:

    错误是由于声明“struct Raw_data_struct”时的混合造成的。你可以看看typedef struct vs struct definitions [duplicate]的帖子。

    要声明你的结构,你必须使用:

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

    而不是:

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

    如果你想同时声明struct和typedef,你必须使用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多