From ISO/IEC 9899:201x部分5.1.2.3 程序执行段落4:
在抽象机中,所有表达式都按以下指定的方式求值
语义。实际的实现不需要评估一部分
表达式,如果它可以推断出它的值没有被使用并且没有
产生所需的副作用 (包括任何由以下原因引起的呼叫一个
函数或访问易失性对象).
关于易失性对象,这里允许的优化到底是什么?有人可以举一个易失性访问的例子吗CAN被优化掉了吗?
由于易失性访问是一种可观察的行为(在段落中描述)6)似乎没有关于挥发物的优化可以采取,所以,我很想知道该部分允许哪些优化4.
稍微重新格式化一下:
An actual implementation need not evaluate part of an expression if:
a) it can deduce that its value is not used; and
b) it can deduce that that no needed side effects are produced (including any
caused by calling a function or accessing a volatile object).
在不改变含义的情况下颠倒逻辑:
An actual implementation must evaluate part of an expression if:
a) it can't deduce that its value is not used; or
b) it can't deduce that that no needed side effects are produced (including
any caused by calling a function or accessing a volatile object).
简化以关注易变部分:
An actual implementation must evaluate part of an expression if needed
side effects are produced (including accessing a volatile object).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)