C Typedef - 不完整类型

Zyy*_*ins 8 c struct typedef header-files incomplete-type

所以,出乎意料的是,编译器决定吐面:"现场客户的类型不完整".

这是相关的代码片段:

customer.c

#include <stdlib.h>
#include <string.h>

#include "customer.h"

struct CustomerStruct;
typedef struct CustomerStruct
{
    char id[8];
    char name[30];
    char surname[30];
    char address[100];
} Customer ;

/* Functions that deal with this struct here */
Run Code Online (Sandbox Code Playgroud)

customer.h

customer.h的头文件

#include <stdlib.h>
#include <string.h>

#ifndef CUSTOMER_H
#define CUSTOMER_H

    typedef struct CustomerStruct Customer;

    /* Function prototypes here */

#endif
Run Code Online (Sandbox Code Playgroud)

这是我的问题所在:

customer_list.c

#include <stdlib.h>
#include <string.h>

#include "customer.h"
#include "customer_list.h"

#include "..\utils\utils.h"


struct CustomerNodeStruct;
typedef struct CustomerNodeStruct
{
    Customer customer; /* Error Here*/
    struct CustomerNodeStruct *next;
}CustomerNode;



struct CustomerListStruct;
typedef struct CustomerListStruct
{
    CustomerNode *first;
    CustomerNode *last;
}CustomerList;

/* Functions that deal with the CustomerList struct here */
Run Code Online (Sandbox Code Playgroud)

这个源文件有一个头文件customer_list.h,但我认为它不相关.

我的问题

在customer_list.c中,在带注释的行中/* Error Here */,编译器会抱怨field customer has incomplete type.

我一整天都在谷歌搜索这个问题,现在我正在拉出我的眼球并将它们与草莓混合.

这个错误的来源是什么?

提前致谢 :)

[PS,如果我忘记提及的话,请告诉我.对你来说,这是一个充满压力的一天,你可能会告诉我们

cni*_*tar 13

将struct声明移动到标题:

customer.h
typedef struct CustomerStruct
{
...
}
Run Code Online (Sandbox Code Playgroud)


use*_*691 6

在C中,编译器需要能够计算出直接引用的任何对象的大小.sizeof(CustomerNode)可以计算的唯一方法是在构建时使编译器可以使用Customer的定义customer_list.c.

解决方案是将结构的定义从中移动customer.ccustomer.h.