GCC warnings for unused global variables
Paul Koning
pkoning@equallogic.com
Fri May 2 15:08:00 GMT 2003
>>>>> "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:
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;
}
?
The answer clearly *must* be NO, otherwise you've just defined
volatile into total uselessness.
paul
More information about the Gcc
mailing list