【问题标题】:error: 'Mystruct' undeclared (first use in this function)错误:“Mystruct”未声明(在此函数中首次使用)
【发布时间】:2011-02-14 16:04:22
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: c gcc


    【解决方案1】:

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

    【讨论】:

    • 非常感谢!我在 C++ 中工作了 9 年,现在在 C 中工作让我发疯,即使是最小的事情!
    猜你喜欢
    • 2016-05-09
    • 2018-10-03
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多