挥发性和编译器优化 [英] Volatile and compiler optimization

查看:129
本文介绍了挥发性和编译器优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否确定地说,动荡的关键字没有什么区别,如果编译器的优化关闭即(GCC -o0 ....)?

Is it OK to say that 'volatile' keyword makes no difference if the compiler optimization is turned off i.e (gcc -o0 ....)?

我已经做了一些样品'C'程序,看之间的差异挥发性和非挥发性只有当编译器优化时,即((GCC -O1 ....)生成的汇编code。

I had made some sample 'C' program and seeing the difference between volatile and non-volatile in the generated assembly code only when the compiler optimization is turned on i.e ((gcc -o1 ....).

推荐答案

没有,就作出这样的说法没有根据的。

No, there is no basis for making such a statement.

挥发性有在标准规定了特定的语义。您声称的gcc -O0 总是产生code,使得每一个变量 - 挥发性或不 - 符合这些语义。这是无法保证;即使它正好是一个特定的程序和 GCC 的特定版本的情况下,很可能改变时,例如,你升级你的编译器。

volatile has specific semantics that are spelled out in the standard. You are asserting that gcc -O0 always generates code such that every variable -- volatile or not -- conforms to those semantics. This is not guaranteed; even if it happens to be the case for a particular program and a particular version of gcc, it could well change when, for example, you upgrade your compiler.

这篇关于挥发性和编译器优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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