允许编译器向标准头文件添加函数吗? [英] Is a compiler allowed to add functions to standard headers?

查看:15
本文介绍了允许编译器向标准头文件添加函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is a C compiler allowed to add functions to standard headers and still conform to the C standard?

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

I read this somewhere, but I can't find any reference in the standard, except in annex 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 提供信息而不是规范......所以它没有帮助.

However, Annex J is informative and not normative... so it isn't helping.

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

So I wonder if it is okay or not for a conforming compiler to add additional functions in standard headers?

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

For example, lets say it adds non-standard itoa to stdlib.h.

推荐答案

在4.一致性"§6中,有:

In 4. "Conformance" §6, there is:

符合标准的实现可能有扩展(包括额外的库函数),只要它们不改变任何严格符合的行为程序.

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

在脚注中直接得出结论:

with the immediate conclusion in a footnote:

这意味着一个符合规范的实现除了那些明确的之外不保留任何标识符在本国际标准中保留.

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

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

The reserved identifiers are described in 7.1.3. Basically, it is everything starting with an underscore and everything explicitly listed as used for the standard libraries.

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

So, yes the compiler is allowed to add extensions. But they have to have a name starting with an underscore or one of the prefixes reserved for libraries.

itoa 不是保留标识符,并且在标准头文件中定义它的编译器不符合要求.

itoa is not a reserved identifier and a compiler defining it in a standard header is not conforming.

这篇关于允许编译器向标准头文件添加函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆