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


Paul Koning <pkoning@equallogic.com> writes:

| >>>>> "Gabriel" == Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
| 
|  Gabriel> 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.
| 
|  Gabriel> They can be optimized out if the program cannot tell the
|  Gabriel> difference.
| 
| I can't tell if you're trying to say something that goes directly
| against the intent of volatile or not, so let's talk about an example:

I'm trying to say that "volatile" is not a *reliable* feature to use
to write robust code with reproducible behaviour.

| static volatile int foo;
| 
| void test (void)
| {
| 	foo = 1;
| 	foo = 1;
| }
| 
| Does your statement mean that you believe the compiler is allowed to
| optimize this into:
| void test (void)
| {
| 	foo = 1;
| }
| ?

If it can determine that does nto change the behaviour of whole
program, yes, it is permitted to do so.

| The answer clearly *must* be NO, otherwise you've just defined
| volatile into total uselessness.

I've not defined anything, it has been all there.

-- Gaby


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