Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

c - Is a compiler allowed to add functions to standard headers?

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

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.

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?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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 is not a reserved identifier and a compiler defining it in a standard header is not conforming.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...