Files
cppdraft_translate/cppdraft/using.md
2025-10-25 03:02:53 +03:00

97 lines
4.8 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[using]
# 16 Library introduction [[library]](./#library)
## 16.4 Library-wide requirements [[requirements]](requirements#using)
### 16.4.3 Using the library [using]
#### [16.4.3.1](#overview) Overview [[using.overview]](using.overview)
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1678)
Subclause [using] describes how a C++ program gains access to the facilities of the
C++ standard library[.](#overview-1.sentence-1)
[[using.headers]](#headers "16.4.3.2Headers") describes effects during translation
phase 4, while [[using.linkage]](#linkage "16.4.3.3Linkage") describes effects during [phase
8](lex.phases "5.2Phases of translation[lex.phases]")[.](#overview-1.sentence-2)
#### [16.4.3.2](#headers) Headers [[using.headers]](using.headers)
[1](#headers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1686)
The entities in the C++ standard library are defined in headers,
whose contents are made available to a translation unit when it contains the appropriate#include preprocessing directive ([[cpp.include]](cpp.include "15.3Source file inclusion"))
or the appropriateimport declaration ([[module.import]](module.import "10.3Import declaration"))[.](#headers-1.sentence-1)
[2](#headers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1698)
A translation unit may include library headers in any order ([[lex.separate]](lex.separate "5.1Separate translation"))[.](#headers-2.sentence-1)
Each may be included more than once, with no effect different from
being included exactly once, except that the effect of including either[<cassert>](assertions.general#header:%3ccassert%3e "19.3.1General[assertions.general]") or [<assert.h>](support.c.headers.general#header:%3cassert.h%3e "17.15.1General[support.c.headers.general]") depends each time on the lexically current definition ofNDEBUG[.](#headers-2.sentence-2)[149](#footnote-149 "This is the same as the C standard library.")
[3](#headers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1712)
A translation unit shall include a header only outside of anydeclaration or definition and,
in the case of a module unit,
only in its [*global-module-fragment*](module.global.frag#nt:global-module-fragment "10.4Global module fragment[module.global.frag]"), and
shall include the header or import the corresponding header unit lexically
before the first reference in that translation unit to any of the entities
declared in that header[.](#headers-3.sentence-1)
No diagnostic is required[.](#headers-3.sentence-2)
[149)](#footnote-149)[149)](#footnoteref-149)
This is the same as the C standard library[.](#footnote-149.sentence-1)
#### [16.4.3.3](#linkage) Linkage [[using.linkage]](using.linkage)
[1](#linkage-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1724)
Entities in the C++ standard library have [external linkage](basic.link "6.7Program and linkage[basic.link]")[.](#linkage-1.sentence-1)
Unless otherwise specified, objects and functions have the defaultextern "C++" linkage ([[dcl.link]](dcl.link "9.12Linkage specifications"))[.](#linkage-1.sentence-2)
[2](#linkage-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1730)
Whether a name from the C standard library declared with
external linkage hasextern "C" orextern "C++" linkage is implementation-defined[.](#linkage-2.sentence-1)
It is recommended that an
implementation useextern "C++" linkage for this purpose[.](#linkage-2.sentence-2)[150](#footnote-150 "The only reliable way to declare an object or function signature from the C standard library is by including the header that declares it, notwithstanding the latitude granted in ISO/IEC 9899:2024, 7.1.4.")
[3](#linkage-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1751)
Objects and functions
defined in the library and required by a C++ program are included in
the program prior to program startup[.](#linkage-3.sentence-1)
[4](#linkage-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1757)
See also[replacement functions](replacement.functions "16.4.5.6Replacement functions[replacement.functions]"),[runtime changes](handler.functions "16.4.5.7Handler functions[handler.functions]")[.](#linkage-4.sentence-1)
[150)](#footnote-150)[150)](#footnoteref-150)
The only reliable way to declare an object or
function signature from the C standard library is by including the header that
declares it, notwithstanding the latitude granted in ISO/IEC 9899:2024, 7.1.4[.](#footnote-150.sentence-1)