5

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?

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • 2
    Related to [Can we apply content not explicitly cited from the normative references to the C++ standard?](http://stackoverflow.com/q/23020323/1708801) – Shafik Yaghmour Oct 10 '14 at 17:04
  • @ShafikYaghmour As far as I understood from the asnwer we can use only a referenced part of C standard as normative reference. Right? –  Oct 10 '14 at 17:11
  • As far as I understand the C++ standard must explicitly refer to a normative reference, we can not refer to part of a normative reference otherwise. – Shafik Yaghmour Oct 10 '14 at 17:13
  • I moved my above comments into my answer, so we can remove these comments now. – Shafik Yaghmour Oct 13 '14 at 19:02

1 Answers1

9

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.

Community
  • 1
  • 1
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • @ShafikYaghmour Particular in the case of `` header we can rely on what the C Standard says about it, does it? –  Oct 10 '14 at 17:22
  • @DmitryFucintv I think this is what [c.limits]/2 wants to tell us: "The contents are the same as the Standard C library header ``" -- as I understand it, "the contents" also covers the specification of the constants etc. – dyp Oct 10 '14 at 17:26