gpt4 book ai didi

c++ - C和C++标准库的关系

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:10:37 26 4
gpt4 key购买 nike

此问题与编程或特定语言概念没有直接关系。我的问题是我们可以使用对 C 的引用吗?国际标准(例如 C11)提供规范引用来描述 C 中的任何概念图书馆 C++ .

更具体地说,在标题中 <climits>N3797::18.3.3 [c.limits] 中定义C library标题进行了描述。但是 C标准提供关于<limits.h>的更全面信息的内容而不是 N3797工作草案。

关于 C library 的一切在 C11 中定义对于 C++ 是正确的C++11 中定义的实现的 C library或者我们不能依赖什么 C标准规定?

最佳答案

对于C 标准库,C++ 回退到C 标准并且对于C++11它回到 C99 而不是 C11,在 C++11 之前,引用的 C 标准是 C90。这在 1.2 Normative references 节中有所介绍,其中说:

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.

并包括:

  • ISO/IEC 9899:1999, Programming languages — C

  • ISO/IEC 9899:1999/Cor.1:2001(E), Programming languages — C, Technical Corrigendum 1

  • ISO/IEC 9899:1999/Cor.2:2004(E), Programming languages — C, Technical Corrigendum 2

  • ISO/IEC 9899:1999/Cor.3:2007(E), Programming languages — C, Technical Corrigendum 3

还说:

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.1

C++ 标准使用术语C 标准库 来指代 C99 和 TC,并在 C++ 与 C 不同时明确说明。

17.2 The C standard library 部分说:

  1. The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to ensure static type safety.
  2. The descriptions of many library functions rely on the C standard library for the signatures and semantics of those functions. In all such cases, any use of the restrict qualifier shall be omitted.

cname 头文件对应于 C 标准库 name.h 文件包含在 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. 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. 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)

limits.h 相关的 climits 内容包含在 18.3.3 部分,并说:

The contents are the same as the Standard C library header . [ Note: The types of the constants defined by macros in are not required to match the types to which the macros refer.—end note ]

请注意,正如我在上面的评论中提到的,规范性引用并不是一个整体,C++ 标准必须明确引用规范性引用才能适用于 C++ 标准。参见 Can we apply content not explicitly cited from the normative references to the C++ standard?了解更多详情。

关于c++ - C和C++标准库的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26304506/

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