tags:

views:

87

answers:

1
int* Register = 0x00FF0000; // Address of micro-seconds timer
while(*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)

+2  A: 

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.

Michael Burr
Indeed, you're probably right. But as part of being a novice, I made a mistake by not paying attention to the `volatile` issue. Now, I must read again all my code which is a lot. My project test deadline is close so I don't have time. So all I got left is to hope for -O0 to save me ...
Dor
@Dor: I think you're not alone (as I implied in my last sentence). So `-O0` may well help save you, but you should really try to get those things straightened out. If not now then on the schedule for post deadline.
Michael Burr
ok, thank you :)
Dor