我无法对编译时错误进行排序。我正在编译C项目。我的main.c
文件有一个#include,它可以获取我正在为我的项目使用的结构的定义。关键是每次我尝试编译我的代码时都会出现错误
struct Mystruct* ps = (struct Mystruct* )malloc( sizeof(Mystruct) ); // I have this
// error at compile time
error: 'Mystruct' undeclared (first use in this function)
为什么编译器无法读取结构定义? 包含文件夹已正确设置
由于
答案 0 :(得分:17)
听起来您需要在表达式中使用sizeof(struct Mystruct)
或在某处使用typedef struct Mystruct Mystruct
。在C中,结构体有自己的命名空间。