简体   繁体   English

C与C ++标准库的关系

[英]Relationship between C and C++ standard library

This question doesn't directly relate to programming or a specific language concept. 这个问题与编程或特定的语言概念没有直接关系。 My question is can we use a reference to the C International Standard (for instance C11 ) to provide a normative reference to describe any concept from a C library in C++ . 我的问题是我们是否可以使用对C国际标准(例如C11 )的引用来提供规范性参考来描述C++ C库中的任何概念。

To be more specific, in a header <climits> defined in N3797::18.3.3 [c.limits] the C library header is described. 更具体地说,在N3797::18.3.3 [c.limits]定义的标题<climits>中描述了C library标题。 But the C Standard provide more comprehensive information about <limits.h> 's content rather than N3797 working draft. 但是C标准提供了有关<limits.h>内容的更全面的信息,而不是N3797工作草案。

So everything about the C library defined in the C11 is true for the C++ implementation defined in C++11 of C library or we can't rely to what the C standard provides? 所以对一切C library中定义的C11是真正的C++中定义的实现C++11C library或者我们不能依赖于什么C标准规定?

For the C standard library C++ falls back on the C standard and for C++11 it falls back on C99 not C11, before C++11 the C standard referenced was C90. 对于C标准库, C ++回退到C标准,对于C ++ 11,它回退到C99而不是C11,在C ++ 11之前引用的C标准是C90。 This is covered in section 1.2 Normative references which says: 1.2 规范性参考文献中对此进行了说明:

The following referenced documents are indispensable for the application of this document. 以下参考文件对于本文件的应用是必不可少的。 For dated references, only the edition cited applies. 凡是注日期的引用文件,仅引用的版本适用。 For undated references, the latest edition of the referenced document (including any amendments) applies. 凡是不注日期的引用文件,其最新版本(包括所有的修改单)适用于本标准。

and includes: 包括:

  • ISO/IEC 9899:1999, Programming languages — C ISO / IEC 9899:1999,编程语言 - C.

  • ISO/IEC 9899:1999/Cor.1:2001(E), Programming languages — C, Technical Corrigendum 1 ISO / IEC 9899:1999 / Cor.1:2001(E),编程语言 - C,技术勘误1

  • ISO/IEC 9899:1999/Cor.2:2004(E), Programming languages — C, Technical Corrigendum 2 ISO / IEC 9899:1999 / Cor.2:2004(E),编程语言 - C,技术勘误2

  • ISO/IEC 9899:1999/Cor.3:2007(E), Programming languages — C, Technical Corrigendum 3 ISO / IEC 9899:1999 / Cor.3:2007(E),编程语言 - C,技术勘误3

and also says: 并且还说:

The library described in Clause 7 of ISO/IEC 9899:1999 and Clause 7 of ISO/IEC 9899:1999/Cor.1:2001 and Clause 7 of ISO/IEC 9899:1999/Cor.2:2003 is hereinafter called the C standard library. ISO / IEC 9899:1999的第7条和ISO / IEC 9899:1999 / Cor.1:2001的第7条以及ISO / IEC 9899:1999 / Cor.2:2003的第7条中描述的库在下文中称为C标准库。 1 1

The C++ standard uses the term C standard library to refer back to C99 and the TCs and will explicitly state when C++ differs from C. C ++标准使用术语C标准库来引用C99和TC,并将明确说明C ++与C的不同之处。

and section 17.2 The C standard library says: 和第17.2C标准库说:

  1. The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to ensure static type safety. C ++标准库还提供C标准库的功能,经过适当调整以确保静态类型安全。
  2. The descriptions of many library functions rely on the C standard library for the signatures and semantics of those functions. 许多库函数的描述依赖于C标准库来获取这些函数的签名和语义。 In all such cases, any use of the restrict qualifier shall be omitted. 在所有这些情况下,应省略对限制限定符的任何使用。

The cname header files which correspond to C Standard Library name.h files is covered in 17.6.1.2 Headers which says amongst other things: 与C标准库name.h文件相对应的cname头文件包含在17.6.1.2 Headers中 ,其中包括:

Except as noted in Clauses 18 through 30 and Annex D, the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in the C standard library (1.2) or the C Unicode TR, as appropriate, as if by inclusion. 除第18条至第30条和附件D中所述外,每个标题cname的内容应与C标准库(1.2)或C Unicode TR中指定的相应标题name.h的内容相同。 ,好像通过包含。 In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace std. 但是,在C ++标准库中,声明(除了在C中定义为宏的名称除外)都在命名空间std的命名空间范围(3.3.6)内。 It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations (7.3.3) 未指定是否首先在全局命名空间范围内声明这些名称,然后通过显式使用声明将其注入命名空间std(7.3.3)

The contents of climits as they relate to limits.h is covered in section 18.3.3 and says: limits.h相关的climits内容将在第18.3.3节中介绍,并说:

The contents are the same as the Standard C library header . 内容与标准C库头相同。 [ Note: The types of the constants defined by macros in are not required to match the types to which the macros refer.—end note ] [注意:宏中定义的常量类型不需要与宏引用的类型相匹配。-end note]

Note, as I mentioned in the comment above, the normative references are not taken as a whole, the C++ standard must make explicit reference to a normative reference for it to apply to the C++ standard. 请注意,正如我在上面的注释中所提到的,规范性引用并未作为一个整体,C ++标准必须明确引用它以适用于C ++标准的规范性引用。 See Can we apply content not explicitly cited from the normative references to the C++ standard? 请参阅我们是否可以将未明确引用的内容应用于C ++标准的规范性引用? for more details. 更多细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM