Hmm... on this point there can be a problem. There are 2 major types of
access read from memory (load) and write to memory (store). It is very
possible to end up performing an optimistic read; only to throw away the
value contained due to a compare/jump. This is usually considered a
safe optimization.
As embedded programmers who have to deal with registers containing
auto-resetting status bits have known for many years, this is not a safe
optimisation at all. We use 'volatile' to suppress it.
NB Marking the variable 'volatile' does not mean anything useful in the
situation you are in. The exact meaning of what 'volatile' is can be a
problem between compilers, but in the case of GCC it can stop the
re-ordering and the caching of value in register aspect of your entire
problem. But it will never enforce the method used to perform the
load/store, not will it (at this time) stop the unintended write-access.
Huh? When I tried compiling the test case, it did exactly that. Hang on,
I'll check: