This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC warnings for unused global variables
> Date: Thu, 1 May 2003 21:11:32 -0700
> From: Richard Henderson <rth@redhat.com>
> On Thu, May 01, 2003 at 08:47:03PM -0700, Geoff Keating wrote:
> > The C standard says:
> >
> > > An object that has volatile-qualified type may be modified in ways
> > > unknown to the implementation or have other unknown side effects.
> >
> > That sounds exactly like a description of the case here: the 'unknown
> > side effect' is that what(1) reads the string.
>
> We don't care about side effects to the object if we never
> access it. You're reading that *way* too far afield.
The sentence refers to side-effects of the object, not of
modifications to the object.
... language lawyering, 5 cents :-)
> > For instance, at program startup (in this case) the abstract machine
> > says the string contains a particular value, and how can it do that if
> > it is optimized away?
>
> Ok, I'll play your game. By the as-if rule, it *does*
> have that value. Any time the program cares to check
> that'll be true.
That's true of all variables, 'volatile' or not. They have to have
the correct value every time the program checks. The difference that
volatile makes is that (in some loosely-defined way) they have to have
the correct value even when the program's not looking, because
something else might be.
--
- Geoffrey Keating <geoffk@geoffk.org>