【问题标题】:DT_REG undeclared (first use in this function) and -std=c99DT_REG 未声明(在此函数中首次使用)和 -std=c99
【发布时间】:2011-07-04 02:50:27
【问题描述】:

我正在使用 Eclipse CDT 编写 C 程序。我想像这样初始化我的 for 循环...

for( int i = 0; i < 5; i++ )

所以我在 gcc 命令行中添加了 -std=c99。这有抛出错误的副作用:'DT_REG' undeclared (first use in this function) for the line:

if( dir_ent->d_type != DT_REG )

DT_REG 在dirent.h(包含在内)中定义。在 gcc 命令行上没有 -std=c99 的代码编译得很好。我错过了什么?

【问题讨论】:

    标签: c


    【解决方案1】:

    -std=gnu99 会发生什么?看起来d_type 字段是非标准的(请参阅the GNU libc manual page "Directory Entries"),因此表示目录条目类型的枚举在严格兼容模式下被禁用。看来您需要定义_BSD_SOURCE(或_GNU_SOURCE)来获取类型值。

    【讨论】:

    • gnu99 成功了。感谢您的链接,它有助于澄清事情。
    猜你喜欢
    • 2012-05-19
    • 2014-04-22
    • 2012-05-07
    • 2012-07-13
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多