gpt4 book ai didi

c - 是否允许编译器向标准头文件添加函数?

转载 作者:太空狗 更新时间:2023-10-29 17:05:48 25 4
gpt4 key购买 nike

是否允许 C 编译器向标准头文件添加函数并仍然符合 C 标准?

我在某处读到过这个,但我在标准中找不到任何引用,除了附件 J.5:

The inclusion of any extension that may cause a strictly conforming program to become invalid renders an implementation nonconforming. Examples of such extensions are new keywords, extra library functions declared in standard headers, or predefined macros with names that do not begin with an underscore.

但是,附件 J 仅供引用而非规范……因此它没有帮助。

所以我想知道符合标准的编译器是否可以在标准头文件中添加额外的功能?

例如,假设它向 stdlib.h 添加了非标准的 itoa。

最佳答案

在4.“Conformance”§6中,有:

A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.

在脚注中直接得出结论:

This implies that a conforming implementation reserves no identifiers other than those explicitly reserved in this International Standard.

保留标识符在 7.1.3 中描述。基本上,它是以下划线开头的所有内容,以及明确列为用于标准库的所有内容。

所以,是的,允许编译器添加扩展。但它们的名称必须以下划线或为库保留的前缀之一开头。

itoa 不是保留标识符,在标准 header 中定义它的编译器不符合标准。

关于c - 是否允许编译器向标准头文件添加函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8270324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com