gpt4 book ai didi

c - 允许对 volatile 对象进行优化

转载 作者:太空狗 更新时间:2023-10-29 15:13:45 25 4
gpt4 key购买 nike

来自 ISO/IEC 9899:201x 部分 5.1.2.3 程序执行4:

In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object).

关于 volatile 对象,这里允许的优化到底是什么?有人可以举一个可以被优化掉的不稳定访问的例子吗?

由于 volatiles 访问是一种可观察到的行为(在 6 段中描述)似乎没有关于 volatiles 的优化可以取悦,所以,我很想知道 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).

关于c - 允许对 volatile 对象进行优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55534512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com