为什么在使用 -std=c99 后 <sys/types.h> 中的 uint 消失了?

4
// 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

然而,以下代码会出现错误:"undeclared uint"。
$gcc -std=c99 test.c
$clang -std=c99 test.c

有人能解释一下为什么在C99标准中,uint的定义消失了吗?

在这个头文件中写明了,如果是"c99"的情况下,int类型会在inttypes.h中定义。 - Eddy_Em
2个回答

6

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


感谢您的提示,我已经为这种行为添加了代码级别的解释。 - Albert Netymk

1

该内容显示在这里,与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的默认标准中包括的结果是可以理解的。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接