This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC warnings for unused global variables


On 02-May-2003, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
> prj@po.cwru.edu (Paul Jarc) writes:
> 
> | Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
> | > Fergus Henderson <fjh@cs.mu.OZ.AU> writes:
> | >| 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).
> | 
> | Accessing a volatile object includes writing, and writing includes
> | initializing.  So the initialization cannot be optimized out.
> 
> Why? the last part of the paragraph quoted above does specifically
> permit that optimization where applicable.

In the case of accesses to volatile objects, it is never applicable.

I think you are misinterpreting the intent of the parenthetical
phrase in the quote above.  I think the mention of volatile there was
added specifically to remind the reader that the optimization is not
permitted if the expression accesses a volatile object.  You seem to be
(mis)interpreting it as allowing the optimization provided that the side
effect was not "needed", while ignoring the fact that the compiler can
never determine that such a side effect is not needed.

-- 
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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]