简体   繁体   English

armcc是否使用-O0优化非易失性变量?

[英]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. 在我看来,无论如何,您都应声明Registervolatile ,因为它是易失的。 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.

相关问题 易失性和非易失性位域 - volatile and non-volatile bitfields 将易失性数组与非易失性数组进行比较 - Comparing a volatile array to a non-volatile array 为什么将未签名的字符声明为“ Volatile”会使它与“非易失性”的未签名字符不兼容? - Why does declaring an unsigned char “Volatile” make it incompatible with a “non-volatile” unsigned char? -O0编译器标志与C中的volatile关键字具有相同的效果吗? - Does the -O0 compiler flag have the same effect as the volatile keyword in C? 通过易失性引用/指针访问声明的非易失性对象是否会在所述访问时赋予易失性规则? - Does accessing a declared non-volatile object through a volatile reference/pointer confer volatile rules upon said accesses? 指针指向非易失性对象的指针行为的要求 - Requirements for behavior of pointer-to-volatile pointing to non-volatile object 将易失性分配给非易失性语义和 C 标准 - Assign volatile to non-volatile sematics and the C standard 指针声明(非易失性存储器)初始化(易失性存储器) - Pointer declaration (non-volatile memory) initialization (volatile memory) gcc -O0仍然优化了“未使用”的代码。是否有一个编译标志来改变它? - gcc -O0 still optimizes out “unused” code. Is there a compile flag to change that? 为什么gcc不删除非易失性变量的检查? - Why doesn't gcc remove this check of a non-volatile variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM