Re: Use of volatile const
- From: jameskuyper@xxxxxxxxxxx
- Date: Tue, 22 Apr 2008 15:51:13 -0700 (PDT)
Douglas A. Gwyn wrote:
James Kuyper wrote:
Douglas A. Gwyn wrote:
The standard already specifies that the accesses must actuallyTrue; but that's not the issue. The issue is what the access will find;
occur, *whether or not a ghost is at work*.
because the standard allows for (as you put it) ghostly intervention,
the access may retrieve a different value from the one last written.
There's no reasonable way for that to happen, but the standard only
requires that the object's definition be volatile-qualified, in order to
allow "ghostly intervention". It doesn't impose other requirements, such
as initializing a pointer to volatile qualified memory with an
implementation-defined special value, or with the return value from an
implementation-defined routine. It simply says "volatile qualified".
My point is that the rest of the standard is still applicable,
and it includes a virtual machine model, sequence points, etc.
Volatile qualification, which can be applied in ways other than
just in object definitions, limits the extent to which the
generated code can deviate from the abstract execution model.
What that rest of the standard says about the virtual machine model,
sequence points, etc, is not sufficient to ensure that the following
code has defined behavior:
int main(void) {int i=0; return i;}
Only 6.2.4p2 guarantees that, when the return statement is reached,
'i' will retain it's last-stored value, in this case 0, which is a
value with defined behavior for a return statement. However, 6.7.3p6
explicitly modifies that guarantee with respect to any object with
volatile-qualified type. As Footnote 26 puts it, "In the case of a
volatile object, the last store need not be explicit in the program."
This means that in principle
int main(void) {volatile int i=0; return i;}
might not have defined behavior, because a store which is not
explicitly in the program might have changed the value of 'i' to one
which cannot be safely used in a return statement.
I didn't understand your last couple of sentences, since I never
said anything about implementation-defined special values etc.
I was just giving examples of plausible ways in which a program could
gain access to truly-volatile memory. My point is, the standard should
clarify what those methods are. As written it says that simply
applying the 'volatile' qualifier to an object declaration is
sufficient to enable stores which are not explicit in the program; and
I'm sure that this was not the intent.
.
- Follow-Ups:
- Re: Use of volatile const
- From: Keith Thompson
- Re: Use of volatile const
- References:
- Use of volatile const
- From: Ian Collins
- Re: Use of volatile const
- From: Douglas A. Gwyn
- Re: Use of volatile const
- From: Richard Tobin
- Re: Use of volatile const
- From: Ian Collins
- Re: Use of volatile const
- From: Richard Tobin
- Re: Use of volatile const
- From: James Kuyper
- Re: Use of volatile const
- From: Douglas A. Gwyn
- Re: Use of volatile const
- From: James Kuyper
- Re: Use of volatile const
- From: Douglas A. Gwyn
- Use of volatile const
- Prev by Date: Re: Use of volatile const
- Next by Date: Re: Preprocessor arithmetic
- Previous by thread: Re: Use of volatile const
- Next by thread: Re: Use of volatile const
- Index(es):
Relevant Pages
|
Loading