开发者

Does armcc optimizes non-volatile variables with -O0?

开发者 https://www.devze.com 2022-12-25 23:04 出处:网络
int* Register = 0x00FF0000; // Address of micro-seconds timer while(*开发者_JAVA百科Register != 0);
int* Register = 0x00FF0000; // Address of micro-seconds timer
while(*开发者_JAVA百科Register != 0);

Should I declare *Register as volatile while using armcc compiler and -O0 optimization ?

In other words: Does -O0 optimization requires qualifying that sort of variables as volatile ? (which is probably required in -O2 optimization)


It seems to me that you should declare Register as volatile regardless, since it is volatile. There's no harm in marking it volatile, since you're depending on the compiler not optimizing away the accesses through the pointer.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号