【问题标题】:Why uint from <sys/types.h> disappears using -std=c99?为什么 <sys/types.h> 中的 uint 使用 -std=c99 会消失?
【发布时间】:2013-03-06 04:05:52
【问题描述】:
// Filename: test.c
#include <sys/types.h>
int main() {
    uint a;
    return 0;
}

上面的代码可以使用 gcc 和 clang 编译,标准如 gnu89 或 gnu99。换句话说,以下工作。

$gcc test.c # for the default is std=gnu89
$clang test.c # for the default is std=gnu99

但是,以下失败并出现错误“未声明的 uint”。

$gcc -std=c99 test.c
$clang -std=c99 test.c

能否解释一下为什么 uint 的定义在 c99 标准中消失了?

【问题讨论】:

  • 在这个头文件中写的比在“c99”的情况下 int 类型在 inttypes.h 中定义。

标签: c standards c99


【解决方案1】:

因为 C 标准没有定义/要求类型 uint。它很可能是编译器、系统或库特定的便利类型。不要使用它。

【讨论】:

  • 感谢您的提示,我已为此行为添加了代码级别的解释。
【解决方案2】:

的内容如here所示,与uint相关的部分介绍为:

#ifdef __USE_MISC
/* Old compatibility names for C types.  */
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
#endif

SO 告诉我们这个特殊宏的来源提供了一些基本解释。

仔细研究表明,SVID 也是一种标准,得到this 的支持。 GNU 标准 gnu89 和 gnu99 可能涵盖了尽可能多的内容,因此 uint 不包含在 C99 中但对于 gcc 和 clang 的默认标准的结果行为是可以理解的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多