Quote:
It's not unheard of for a compiler to do this even for non-constant variables
Yes, that's one of the major trouble when doing embedded device programming. For instance, you're mapping a hardware register. Your compiler has absolutely no chance to guess that the variable used for this - though not modified by your code - can be actually be changed by the HW. So you need to tell the compiler explicitly about this fact using volatile.
Thinking a bit more, I believe that "const volatile" has a
raison d'être, at least for embedded code. You're just saying: "my program isn't supposed to modify this variable" but "this variable can be changed by external source, like HW".
Thanks Corona for your point!
Cheers, Loïc