C++研究笔记(4)实现遵从性

类别:编程语言 点击:0 评论:0 推荐:

C++ 编译器作为 C++ 标准的实现,依据 C++ 标准的可诊断规则和库定义。C++ 标准指出:

1.4 Implementation compliance [intro.compliance]

The set of diagnosable rules consist of all syntactic and semantic rules in this Internationa Standard except for those rules containing an explicit notation that “no diagnostic is required” or which are described as resulting in “undefined behavior.”
“可诊断规则”的集合是由除了被明确标记为“无需诊断”或以导致“未定义行为”来描述的规则外,本标准中的所有语法的和语义的规则组成。

Although this International Standard states only requirements on C++ implementations, those requirements are often easier to understand if they are phrased as requirements on programs, parts of programs, or execution of programs. Such requirements have the following meaning:
虽然本标准只是陈述了 C++ 实现的规格,但将它们当作程序,程序片段,程序的执行的规格通常更容易理解。这些规格包含以下意义:

If a program contains no violations of the rules in this International Standard, a conforming implementation shall, within its resource limits, accept and correctly executei) that program.
如果一个程序不违反本标准的规则,符合标准的实现应该在其资源限制条件下,接受并正确执行i)这个程序。
i)“Correct execution” can include undefined behavior, depending on the data being procesed; see 1.3 and 1.9.
“正确执行”也可能产生未定义行为,这随被程序处理的数据而定。参见 1.3 和 1.9。 If a program contains a violation of any diagnosable rule, a conforming implementation shall issue a least one diagnostic message, except that
如果一个程序违反了任何可诊断规则,符合标准的实现应该给出至少一条诊断消息,除非 If a program contains a violation of a rule for which no diagnostic is required, this International Standard places no requirement on implementations with respect to that program.
如果一个程序违反了无需诊断的规则,本标准对这个程序不向实现施以任何规格。

For classes and class templates, the library clauses specify partial definitions. Private members (clause 11) are not specified, but each implementation shall supply them to complete the definitions according to the description in the library clauses.
对于类和模板类,标准库章节仅规定了它们的部分定义。虽然没有具体规定,但每个实现都应该提供私有成员(章节11)以按照标准库章节的描述将定义完成。

For functions, function templates, objects, and values, the library clauses specify declarations. Implementations shall supply definitions consistent with the descriptions in the library clauses.
对于函数,函数模板,对象和值,标准库章节规定了它们的声明。每个实现都应该提供与标准库章节的描述一致的定义。

The names defined in the library have namespace scope (7.3). A C++ translation unit (2.1) obtains access to these names by including the appropriate standard library header (16.2).
在标准库中定义的名字具有名字空间作用域(7.3)。C++ 编译单元(2.1)可通过包含相应的标准库头文件(16.2)来获取访问这些名字的能力。

The templates, classes, functions, and objects in the library have external linkage (3.5). The implementation provides definitions for standard library entities, as necessary, while combining translation units to form a complete C++ program (2.1).
标准库中的模板,类,函数和对象具有外部连接(3.5)。当组合编译单元称为一个完整 C++ 程序(2.1)时,实现应该根据需要提供标准库实体的定义。

Two kinds of implementations are defined: hosted and freestanding. For a hosted implementation, this International Standard defines the set of available libraries. A freestanding implementation is one in which execution may take place without the benefit of an operating system, and has an implementation-defined set of libraries that includes certain language-support libraries (17.4.1.3).
本标准定义了两类实现:寄生实现和原生实现。本标准为寄生实现定义了可用的标准库。原生实现中的程序执行没有操作系统的支持,带有包含特定语言支持库的一组实现定义的库。

A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any well-formed program. Implementations are required to diagnose programs that use such extensions that are ill-formed according to this International Standard. Having done so, however, they can compile and execute such programs.
符合标准的实现可以带有扩展(包括附加的库功能),只要这些扩展不会改变任何完备程序的行为。实现应该将使用这些扩展的程序诊断成依据本标准为病态的。然而,这些程序据此可以被编译和执行。

本文地址:http://com.8s8s.com/it/it26150.htm