[英]Does armcc optimizes non-volatile variables with -O0?
int* Register = 0x00FF0000; // Address of micro-seconds timer
while(*Register != 0);
Should I declare *Register
as volatile
while using armcc compiler and -O0 optimization ? 使用armcc编译器和-O0优化时,我应该将*Register
声明为volatile
吗?
In other words: Does -O0 optimization requires qualifying that sort of variables as volatile
? 换句话说:-O0优化是否需要将这种变量限定为volatile
? (which is probably required in -O2 optimization) (这可能是-O2优化所必需的)
It seems to me that you should declare Register
as volatile
regardless, since it is volatile. 在我看来,无论如何,您都应声明Register
为volatile
,因为它是易失的。 There's no harm in marking it volatile
, since you're depending on the compiler not optimizing away the accesses through the pointer. 将其标记为volatile
没有什么害处,因为您依赖于编译器而不是优化通过指针的访问。
int volatile* Register = (int*) 0x00FF0000;
You shouldn't depend on the compiler optimization settings to hope this gets compiled correctly. 您不应该依赖编译器优化设置来希望它能够正确编译。 I'd guess that forgetting to mark things volatile
appropriately is a major reason that cranking up optimizations on embedded C code often causes things to start breaking. 我猜想忘记适当地标记volatile
是在嵌入式C代码上加速优化通常会导致事物开始崩溃的主要原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.