volatile structures: Is that a bug?
Andrew Haley
aph@redhat.com
Fri Sep 19 16:07:00 GMT 2008
Etienne Lorrain wrote:
>>> On C structures, for attributes like "const", it is enough to
>>> consider that each field inherit the attribute of the structure.
>>> But for the volatile attribute, is it valid to treat each field as
>>> volatile like GCC does it now?
>> "An object that has volatile-qualified type may be
>> modified in ways unknown to the implementation or
>> have other unknown side effects. Therefore any
>> expression referring to such an object shall be
>> evaluated strictly according to the rules of the abstract
>> machine, as described in 5.1.2.3."
>>
>> So, any reference to the object must treat the object as
>> volatile, and that includes any reference to any part of
>> the object.
>
> If I correctly understand you, GCC is wrong reading a byte when the
> byte is part of a volatile structure - GCC needs to read the complete
> structure first, and then extract the byte.
I didn't say that. Neither did the standard, by my reckoning.
Please read the standard, in particular the part that follows.
Andrew.
More information about the Gcc
mailing list