- 论坛徽章:
- 0
|
本帖最后由 幻の上帝 于 2012-06-21 22:05 编辑
回复 260# kzl0629
很简单,这里的implementation-defined决定的只是suggestion中的哪些是effective的extent,没有涉及决定是否能拒绝接受代码的能力。
ISO C11(N1570)
6.7.1
Semantics
6 A declaration of an identifier for an object with storage-class specifier register suggests that access to the object be as fast as possible. The extent to which such suggestions are effective is implementation-defined.
而事实上,即便这里说的没有那么明确,以implementation-defined(这里只可能是指behavior而不是value)确定是否接受代码也是不可能的,除非标准明确另行规定实现可以选择接受或不接受这个代码的这两种明确选择。
ISO C11(N1570)
3.4.1
1 implementation-defined behavior
unspecified behavior where each implementation documents how the choice is made
3.4.4
1 unspecified behavior
use of an unspecified value, or other behavior where this International Standard provides two or more possibilities and imposes no further requirements on which is chosen in any instance
ISO C中,implementation-defined behavior是unspecified behavior的子集。所以要说implementation-defined behavior,那么必然是unspecified behavior,必须给出choices。但这里没有。
从另一个角度来讲,这里无论是否接受,实现都没有义务给出诊断消息,因为这里显然不会是语法错误,上面的小标题是semantics而不是constraints:
3.8
1 constraint
restriction, either syntactic or semantic, by which the exposition of language elements is to be interpreted
5.1.1.3 Diagnostics
1 A conforming implementation shall produce at least one diagnostic message (identified in an implementation-defined manner) if a preprocessing translation unit or translation unit contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined. Diagnostic messages need not be produced in other circumstances.9)
9) The intent is that an implementation should identify the nature of, and where possible localize, each violation. Of course, an implementation is free to produce any number of diagnostics as long as a valid program is still correctly translated. It may also successfully translate an invalid program.
剩下可以认为允许接受但不保证正确的(且不给出诊断消息的),只有undefined behavior了:
3.4.3
1 undefined behavior
behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements
但一个undefined behavior显然不是unsepcified behavior,更别提是implementation-defined behavior了:
4/3 A program that is correct in all other aspects, operating on correct data, containing unspecified behavior shall be a correct program and act in accordance with 5.1.2.3.
|
|