错误:不完全类型不允许
问题描述:
在.H:错误:不完全类型不允许
typedef struct token_t TOKEN;
在.C:
#include "token.h"
struct token_t
{
char* start;
int length;
int type;
};
在main.c中:
#include "token.h"
int main()
{
TOKEN* tokens; // here: ok
TOKEN token; // here: Error: incomplete type is not allowed
// ...
}
我得到的错误最后一行:
Error: incomplete type is not allowed
怎么了?
答
在主模块中没有定义结构。你必须包括它的头,编译器不知道多少内存分配给了这个定义
TOKEN token;
由于结构的大小是未知的。未知大小的类型是不完整类型。
例如,你可以在头
typedef struct token_t
{
char* start;
int length;
int type;
} TOKEN;
发布与你正在编译 – danish 2014-10-18 11:47:17