出现这个错误的原因是sizeof对应的类型不确定
例如:
file.h
#ifndef file_h
#define file_h
struct file_name_;
typedef struct file_name_ file_name;
struct file_name_head_
typedef struct file_name_head_ file_name_head;
#endif
file.c
#include "file.h"
struct file_name_ {
char name[512];
struct file_name_ *next;
};
struct file_name_head_ {
struct file_name_ *first
};
main.c
#include "file.h"
int main()
{
file_name_head *head = (file_name_head *) malloc (sizeof(file_name_head));
}
出现这个问题的原因是file_name_head在main.c文件中只是一个名字,没有完成的类型,必须要把这个类型完整的声明道头文件中,这样才能全部识别