avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] avr-g++ local variable constructor / block body/ dest


From: David Brown
Subject: Re: [avr-gcc-list] avr-g++ local variable constructor / block body/ destructor execution order
Date: Mon, 17 Sep 2007 00:34:06 +0200
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

Graham Davies wrote:
David Brown wrote:
I believe [the compiler] can [change order of ... volatile objects access]. Obviously it is only legal if such moves do not affect the volatile accesses themselves. Perhaps someone here who has a better knowledge of the standards ...

I wouldn't claim better knowledge, but this is a sore spot for me so I'm going to chime in anyway.

I think that the compiler is not permitted to change the order in which volatile objects are accessed. This would undermine the intent of volatile, which is to give the user exactly what he asks for. My impression is that the C language is defined in terms of the behavior of an abstract machine, which lacks all optimization and operates in a very simplistic but easy-to-describe manner. An actual compiler is allowed to deviate from this, in order to perform optimization, on condition that the resulting behavior is indistinguishable from the abstract machine at certain places called sequence points. In addition, when manipulating volatile objects, it is not allowed to deviate at all from the abstract machine.

Graham.


That's pretty much the same as my understanding. But I don't think there is any need for the action of the generated program to match that of the simple abstract machine except when the effects are visible by something other than the code the compiler has control over in this translation unit. Thus at a sequence point, any writes to externally linked variables (i.e., anything non-static) must be completed - but there is no need to complete writes to static variables (they can be completely removed by the optimiser sometimes). The order of these writes is not determined, unless the variables are volatile. The compiled code must simply complete a snapshot of the externally visible abstract machine before each sequence point.

mvh.,

David





reply via email to

[Prev in Thread] Current Thread [Next in Thread]