开发者

Is the C++ Standard Library part of the C++ Language?

Is the C++ Standard Library part of the C++ Language? (note "language", not "standard"; both are, of course, part of the standard).

If so, wh开发者_Python百科y? If not, why not?

The answer to this question may differ across C++98, C++03 and C++0x.

It's not subjective because it can be inferred from wording/requirements in the relevant standards documents.


Yes, in both the current standard (C++03) and the new upcoming one (C++0x, which has at last reached the final draft stage so it shouldn't be too long now), the library functions are part of the specification (at least for the hosted implementations). Even freestanding implementations require a standard library, albeit a much simpler one.

In C++03, chapters 17 through 27 deal with the standard library. In C++0x (at least the n3225 draft which is the latest I have handy), chapters 17 through to 30 are relevant.

You can see the standards for C++03 and the current C++0x draft to confirm this. The standards contain both the language proper and the standard library.

From C++03 (which is pretty much the same as C++0x for this section):

1.1 Scope [intro.scope]

1 This International Standard specifies requirements for implementations of the C++ programming language. The first such requirement is that they implement the language, and so this International Standard also defines C++. Other requirements and relaxations of the first requirement appear at various places within this International Standard.

2 C++ is a general purpose programming language based on the C programming language as described in ISO/IEC 9899:1990 Programming languages – C (1.2). In addition to the facilities provided by C, C++ provides additional data types, classes, templates, exceptions, namespaces, inline functions, operator overloading, function name overloading, references, free store management operators, and additional library facilities.

So you can see from this that the standards authors do make a distinction between the language proper and the library but, for the implementors of the standard and users of the language, the language is the whole thing. You cannot call yourself C++ unless you follow the standard and the standard requires both the language proper and the library.


The very first words in all of the versions of the standard I've seen are "This International Standard specifies requirements for implementations of the C++ programming language." In other words, anything specified in the standard is part of the "language".

In other places, the standard does distinguish between the library and the rest of the language. Formally, however, the only real distinction is that the library is defined in terms of the non-library parts of the language; i.e. the library defines classes and templates. The standard also makes it clear that the library need not be present as a library, in the form of header files, and parts, or all of it may be built into the compiler (although I'm not aware of any compiler which actually does so).


At least they are not separate!

In several places the language clauses of the standard make use of types and interfaces defined in the library clauses. How could it do that if they were separate entities?

For example the construct

std::vector<int> v = {1, 2, 3, 4, 5};

uses std::initializer_list from the library.

The new expression

char* p = new char[42];

uses operator new from <new>.

The operator typeid returns std::type_info, a library type.

The core feature dynamic_cast might throw an exception, defined in the library.

Some parts of the library, like type_traits and atomic cannot be implemented as just a library, so they are definitely not separate.


Yes - you can find the Library specified in the C++ Standard. Sometimes, you'll run into term "core language features" to distinguish them from library features, but they are both parts of the language.

[EDIT] Actually, the Standard itself seems to make distinction between the language and the library. From the latest draft of C++0x (1.5)

Clauses 2 through 16 describe the C++ programming language. That description includes detailed syntactic specifications in a form described in 1.6. For convenience, Annex A repeats all such syntactic specifications. 2 Clauses 18 through 30 and Annex D (the library clauses) describe the Standard C++ library. That description includes detailed descriptions of the templates, classes, functions, constants, and macros that constitute the library, in a form described in Clause 17.

[/EDIT]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜