Yar*_*lov 2 c data-structures incomplete-type
请指教,怎么了?
在.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);
Run Code Online (Sandbox Code Playgroud)
在.c中
void Getst_resp(Getst_struct Data) //Here Error: incomplete type is not allowed
{
};
Run Code Online (Sandbox Code Playgroud)
小智 5
该错误是由于在声明“ struct Raw_data_struct”时混合引起的。您可以看一下typedef struct vs struct definitions的文章。
要声明您的结构,您必须使用:
struct Raw_data_struct {
uint8_t time;
uint8_t type;
uint8_t phase;
uint8_t status;
};
Run Code Online (Sandbox Code Playgroud)
代替 :
struct {
uint8_t time;
uint8_t type;
uint8_t phase;
uint8_t status;
} Raw_data_struct;
Run Code Online (Sandbox Code Playgroud)
如果要同时声明struct和typedef,则必须使用:
typedef struct Raw_data_struct {
uint8_t time;
uint8_t type;
uint8_t phase;
uint8_t status;
} Getst_struct;
Run Code Online (Sandbox Code Playgroud)