简体   繁体   中英

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

To be more specific, in a header <climits> defined in N3797::18.3.3 [c.limits] the C library header is described. But the C Standard provide more comprehensive information about <limits.h> 's content rather than N3797 working draft.

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?

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. This is covered in section 1.2 Normative references which says:

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/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

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

and section 17.2 The C standard library says:

  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.

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:

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)

The contents of climits as they relate to limits.h is covered in section 18.3.3 and says:

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 ]

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. See Can we apply content not explicitly cited from the normative references to the C++ standard? for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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