This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: volatile [was: GCC warnings for unused global variables]
On 08-May-2003, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
> Fergus Henderson <fjh@cs.mu.oz.au> writes:
> | The C standard text which you quoted doesn't say that the optimization
> | is permitted unconditionally. It only says that the optimization is
> | permitted only "if [the implementation] can deduce that [the expression's]
> | value is not used and that no needed side effects are produced". In the
> | case of volatile variables, this condition is always false,
>
> No, because the standard does specifically add
>
> INCLUDING ANY CAUSED BY CALLING A FUNCTION OR ACCESSING A VOLATILE
> OBJECT
Yes, it says that, but that is just to remind the reader that
accessing a volatile object is a side effect.
You are assuming that the set of side effects produced by accessing
volatile variables which the implementation can deduce are not needed
is a non-empty set. This is not the case. The standard specifically
says so in 6.7.3 paragraph 6 (quoted again below).
> The definition of "volatile" does not say that the implementation can
> never know if a side effect is needed.
I firmly believe that was the intent behind these words:
| 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.
(This belief is not based on any specific statements of the C committee
members, but rather on the general principles that they're not idiots
and that they intended the words that they wrote to be meaningful.)
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.