Loveny Design wrote:
David Brown wrote:
The point is, the compiler is allowed to do this sort of optimisation.
It can be a bit annoying during testing and debugging - especially
because such reorderings are relatively rare in practice, so that it's
easy to think "it worked before, what's wrong now?".
I wouldn't have thought the compiler was allowed to re-order statements
*around* a volatile access. Perhaps someone can help my understanding, given
:-
1: Volatile Statements<sp>
2: Statements<sp>
3: Volatile Statements<sp>
where <sp> is a sequence point.
Line 3 has a volatile access and therefore has side-effects that the
compiler doesn't know about, so surely it must complete all preceeding
statements up to and including the sequence point before the volatile access
occurs?
Jon
No - volatile only enforces ordering with respect to volatile accesses
and anything that might affect them. So if the statements in 2 are
known not to have side effects or read from memory, then they cannot
affect the volatile statements, and thus can be moved around them.
People often think the same thing about embedded assembly statements,
and get surprised when gcc re-orders them.
_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list