c - 错误 : 'Mystruct' undeclared (first use in this function)

标签 c gcc

我无法对编译时错误进行排序。我正在编译 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)

为什么编译器无法读取结构定义? 包含文件夹设置正确

谢谢

最佳答案

听起来您需要在表达式中使用 sizeof(struct Mystruct) 或在某处使用 typedef struct Mystruct Mystruct。在 C 中,结构有自己的命名空间。

关于c - 错误 : 'Mystruct' undeclared (first use in this function),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4994318/

相关文章:

Linux/海湾合作委员会 : ldd functionality from inside a C/C++ program

c - gcc:-pedantic 找不到的非 ISO 实践的例子有哪些?

c - 什么代码CPU比较贵: while(*p) or while(i--)?

c - 是否可以构建交互式 C shell?

c - 使用c在linux上以 block 的形式读写

Java比C快?

c++ - Mac 终端编译错误

c - 为什么 "initializer element is not a constant"……不再工作了?

c++ - 修改 "__cxa_allocate_exception"没有使用malloc

c++ - 如何将 Node.js 解释器嵌入到 C/C++ 中?