stdint.h 和 C99

stdint.h and C99

我在 C99 standard 中读到 stdint.h 是 C 标准库的一部分。

我没看错吗,如果我测试 C99 合规性,使用:

defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)

这意味着 stdint.h 应该可用?

举个恰当的例子:我可以考虑假装 C99 合规但不提供 stdint.h 的环境与其自身的合规性声明不一致,因此存在错误吗?

Edit :对于好奇的人,有问题的系统是带有 HP C 编译器的 OpenVMS(不是 gcc,在 openVMS 上确实提供 stdint.h)。因此,根据目前收到的答复和评论,我必须将此实现(假装是 C99)视为错误。更多详情:https://groups.google.com/forum/#!topic/comp.os.vms/Bnh3tIOc7bo%5B101-125%5D

是的。

顺便说一句,未定义的符号在预处理器表达式中扩展为 0,因此您可以只写:

#if __STDC_VERSION__ >= 199901L

另一方面,声称符合 C99(或 C11)的实现可能仍支持 <stdint.h> 作为扩展。

stdint.h任何 强制执行的少数header之一。甚至各种不起眼的嵌入式系统编译器 可以做到这一点。参见规范文本 C11 第 4/6 章:

A conforming hosted implementation shall accept any strictly conforming program. A conforming freestanding implementation shall accept any strictly conforming program in which the use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>.

所以您可以测试 __STDC_VERSION__ >= 199901L 确实如此,然后 header 必须可用。请注意 inttypes.h.

没有这样的要求

Case in point: can I consider an environment which pretends to be C99 compliant but doesn't provide stdint.h to be at odds with its own compliance statement (and hence buggy)?

是的。