简体   繁体   English

C++ 标准中“好像”规则的陈述或基础在哪里?

[英]Where are the statement of or the foundations for the “as if” rule in the C++ Standard?

After a little google search (for instance, site:eel.is "as if rule" ) I couldn't find a proper place where the so called "as if" rule is clearly stated in the C++ standard.经过一点谷歌搜索(例如, site:eel.is "as if rule" ),我找不到在 C++ 标准中明确说明所谓的 "as if" 规则的合适位置。 All I could find is that in those places within the standard where it is invoked, the intro.execution reference is given.我所能找到的只是在标准中调用它的那些地方,给出了intro.execution参考。

But intro.execution doen't seem to clearly reference any general form of this rule.但是intro.execution似乎并没有明确引用该规则的任何一般形式。 I'm probably missing something subtle here, but can you point me to the place, or places, where a precise normative understanding of the rule is conveyed?我可能在这里遗漏了一些微妙的东西,但是你能指出我对规则的精确规范理解的地方吗? Maybe the whole intro.execution is indeed intended to convey what we call as the "as if" rule in the wild?也许整个intro.execution确实是为了传达我们所谓的“好像”规则? I confess that I've just skimmed through it.我承认我只是略过它。

I'm using this website to navigate through the working draft of the standard.我正在使用这个网站浏览标准的工作草案。

The definition of the "as if" rule can be found, for instance in the cppreference site , as something to the effect that compilers are allowed to perform transformations on programs as long as some constraints are met, for optimizations reasons, for instance.例如,可以在cppreference 站点中找到“好像”规则的定义,即只要满足某些约束条件,例如出于优化原因,编译器就可以对程序执行转换。

The definition for "as if" rule is given in the footnote to 4.1.1/1. “好像”规则的定义在 4.1.1/1 的脚注中给出。 See http://eel.is/c++draft/intro.abstract#footnote-4 :http://eel.is/c++draft/intro.abstract#footnote-4

This provision is sometimes called the “as-if” rule, because an implementation is free to disregard any requirement of this document as long as the result is as if the requirement had been obeyed, as far as can be determined from the observable behavior of the program.这个规定有时被称为“好像”规则,因为只要结果是好像该要求已被遵守,只要可以从可观察到的行为中确定,实施就可以自由地忽略本文档的任何要求。该程序。 For instance, an actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no side effects affecting the observable behavior of the program are produced.例如,如果一个实际的实现可以推断出它的值没有被使用并且没有产生影响程序可观察行为的副作用,那么它就不需要评估表达式的一部分。

From a different Draft Standard , it would appear that the section you refer to in your link actually is the "as-if" rule (see the footnote #5):从不同的Draft Standard看来,您在链接中引用的部分实际上是“as-if”规则(参见脚注 #5):

1.9 Program execution [intro.execution] 1.9 程序执行 [intro.execution]

The semantic descriptions in this International Standard define a parameterized nondeterministic abstract machine.本国际标准中的语义描述定义了一个参数化的非确定性抽象机。 This International Standard places no requirement on the structure of conforming implementations.本国际标准对一致性实现的结构没有要求。 In particular, they need not copy or emulate the structure of the abstract machine.特别是,它们不需要复制或模仿抽象机器的结构。 Rather, conforming implementations are required to emulate (only) the observable behavior of the abstract machine as explained below.相反,需要符合要求的实现来模拟(仅)抽象机的可观察行为,如下所述。 5 . 5 .
... ...
5) This provision is sometimes called the “as-if” rule, because an implementation is free to disregard any requirement of this International Standard as long as the result is as if the requirement had been obeyed, as far as can be determined from the observable behavior of the program. 5) 该条款有时被称为“好像”规则,因为只要结果是好像已经遵守了该要求,实施可以随意忽略本国际标准的任何要求,只要可以从程序的可观察行为。 For instance, an actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no side effects affecting the observable behavior of the program are produced.例如,如果一个实际的实现可以推断出它的值没有被使用并且没有产生影响程序可观察行为的副作用,则它不需要评估表达式的一部分。

PS: One thing I found 'interesting' in this quoted document is the index entry for "as-if rule": PS:我在引用的文档中发现“有趣”的一件事是“as-if rule”的索引条目:

program execution, 8–11
    abstract machine, 8
    as-if rule, see as-if rule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM