允许对易失性对象进行优化 [英] Optimization allowed on volatile objects

查看:78
本文介绍了允许对易失性对象进行优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 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).

在这里,关于易失性对象的允许的优化到底是什么?有人可以举个例子说明可以进行优化的易失性访问吗?

What exactly is the allowed optimization here regarding the volatile object? can someone give an example of a volatile access that CAN be optimized away?

由于挥发物访问是一种可观察到的行为(在第 6 段中进行了描述),因此似乎没有关于该挥发物的优化可以讨价还价,因此,我很想知道在部分中允许进行哪些优化> 4 .

Since volatiles access are an observable behaviour (described in paragraph 6) it seems that no optimization can take please regarding volatiles, so, I'm curious to know what optimization is allowed in section 4.

推荐答案

有人可以举一个可以优化的易失性访问示例吗 离开吗?

can someone give an example of a volatile access that CAN be optimized away?

我认为您对文本有误解,IMO这一段意味着

I think that you misinterpreted the text, IMO this paragraph means that

volatile unsigned int bla = whatever();

if (bla < 0) // the code is not evaluated even if a volatile is involved

这篇关于允许对易失性对象进行优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆