挥发性和编译器优化 [英] Volatile and compiler optimization
问题描述
是否确定地说,动荡的关键字没有什么区别,如果编译器的优化关闭即(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屋!