This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC warnings for unused global variables
Fergus Henderson <fjh@cs.mu.OZ.AU> writes:
[...]
| > C++98 1.9/1:
| >
| > The semantic descriptions in this International Standard define a
| > parameterized nondeterministic abstract machine. This International
| > Standard places no requirement on the structure of conforming
| > implementa-tions. In particular, they need not copy or emulate the
| > structure of the abstract machine. Rather, conform-ing
| > implementations are required to emulate (only) the observable
| > behavior of the abstract machine as explained below.5)
| >
| > There is nothing there that prevents the compiler to apply the "as-if"
| > rule to to volatile objects. The only thinr that is required is to
| > emulate the observable behavuour". The implementation is free to
| > implement whatever it likes as far as the observable behaviour is
| > preserved.
|
| But reads and writes to volatile variables are defined to be *part of*
| "the observable behaviour" (C++98 1.9 paragraph 6). So they can't be
| optimized away under the as-if rule.
They can be optimized out if the program cannot tell the difference.
[...]
| ignored the intent of volatile. I don't think the committee ever
| intended to allow implementations to optimize away volatile variables,
Why not? The C standard clearly says:
[#3] In the abstract machine, all expressions are evaluated
as specified by the semantics. An actual implementation
need not evaluate part of an expression if it can deduce
that its value is not used and that no needed side effects
are produced (including any caused by calling a function or
accessing a volatile object).
That is clear.
| and so the lack of clear wording in the current standard explicitly
| prohibiting this may be just oversight.
or not. See above.
-- Gaby