Article View: comp.std.c
Article #1100Re: A volatile question
From: Ronald Guilmette
Date: Mon, 19 Mar 1990 08:51
Date: Mon, 19 Mar 1990 08:51
50 lines
2421 bytes
2421 bytes
In article <11143@june.cs.washington.edu> pardo@june.cs.washington.edu (David Keppel) writes:
>I have a question about the meaning of ``volatile''. Suppose:
>
> foo (volatile int *zork) { ... }
>
> bar()
> {
> int zork;
> foo (&zork);
> ...
> }
>
>The behavior that I want is that `zork' can be cached (e.g., in a
>register) in `bar'...
Lets backup. Your questions are imprecise.
Obviously, the value of the two different things called "zork" are *never*
considered volatile. To be more precise, the value pointed to by the
"zork" value in bar is considered to be non-volatile, while the value pointed
to by the "zork" in foo is considered to be volatile.
I assume that your questions are really about the pointed to value.
Within bar, new values assigned to the "pointed to" variable need not always be
stored to memory when the abstract semantics of the virtual C machine would
make you think that they should be.
Likewise, within bar, the current value of the "pointed to" variable need not
always be (again) loaded from memory when the abstract semantics of the
virtual C machine would make you think that they should be.
Within foo however, loads and stores of the variable "pointed to" by the
formal parameter named "zork" must be done in an order such that the ordering
of these loads and stores is "correct" relative to other loads and stores of
other volatile variables.
>...but that it must be treated as `volatile' in
>`foo'. If the optimizer is allowed to to optimize away the
>`volatileness' of zork inside `foo'?
Zork is not volatile. The thing that the zork parameter of foo() points to
is considered volatile. The optimizer cannot ignore or override this fact.
Doing so would be a direct violation of the standard, and any implementation
that did this would be non-conforming.
// Ron Guilmette (rfg@ics.uci.edu)
// C++ Entomologist
// Motto: If it sticks, force it. If it breaks, it needed replacing anyway.
Technical Details
Message-ID:
<26049D7B.5953@paris.ics.uci.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!jarthur!uci-ics!rfgReferences:
<11143@june.cs.washington.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!jarthur!uci-ics!rfg From: rfg@ics.uci.edu (Ronald Guilmette) Newsgroups: comp.std.c Subject: Re: A volatile question Message-ID: <26049D7B.5953@paris.ics.uci.edu> Date: 19 Mar 90 08:51:07 GMT References: <11143@june.cs.washington.edu> Reply-To: rfg@ics.uci.edu (Ronald Guilmette) Organization: UC Irvine Department of ICS Lines: 50