C undefined behavior fix
<<Ah... so (paraphrasing) -- if you have two byte size volatile objects, and they happen to end up adjacent in memory, the compiler is explicitly forbidden from turning an access to one of them into a wider access -- because that would be an access to both of them, which is a *different* side effect. (Certainly that exactly matches the hardware-centric view of why "volatile" exists.) And the compiler isn't allowed to change side effects, including causing them when the source code didn't ask you to cause them.
Quoted 1 line
Quoted 1 line
Right, and as you see that is covered by the language on external effects in the Ada standard (remember the intent in Ada was to exactly match the C rules :-)
But one thing in the Ada world that we consider left open is whether a compiler is free to combine two volatile loads into a single load. Probably the answer should be no, but the language at least in the Ada standard does not seem strong enough to say this.
Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"dewar" == dewar <[email protected]> writes:
<<Ah... so (paraphrasing) -- if you have two byte size volatile objects, and they happen to end up adjacent in memory, the compiler is explicitly forbidden from turning an access to one of them into a wider access -- because that would be an access to both of them, which is a *different* side effect. (Certainly that exactly matches the hardware-centric view of why "volatile" exists.) And the compiler isn't allowed to change side effects, including causing them when the source code didn't ask you to cause them.
dewar> Right, and as you see that is covered by the language on dewar> external effects in the Ada standard (remember the intent in dewar> Ada was to exactly match the C rules :-)
dewar> But one thing in the Ada world that we consider left open is dewar> whether a compiler is free to combine two volatile loads into dewar> a single load. Probably the answer should be no, but the dewar> language at least in the Ada standard does not seem strong dewar> enough to say this.
Would ordering rules help answer that? If you write two separate loads you have two separate side effects that are ordered in time, while for a single big load they occur concurrently. If the construct where those two loads occur does not allow for side effects to be interleaved, then the "as if" principle seems to say you cannot legally merge the loads.
paul