Re: volatile Info
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Thu, 05 Aug 2010 00:00:42 +0100
Keith Thompson <kst-u@xxxxxxx> writes:
Ben Bacarisse <ben.usenet@xxxxxxxxx> writes:
Walter Banks <walter@xxxxxxxxxxxxx> writes:[...]
[...]The volatile variable in the example has a very limited scope
which essentially prevents it from being altered.
This is the bit I don't follow. What has the small scope got to do with
it? Is this the same:
extern volatile int clock;
The scope is, if anything, even shorter but this seems like a normal use
I'd say that it's not the scope but the lifetime that's relevant.
I though that might be Walter's point but he has replied now and it
In your example, ``clock'' (whose name conflicts with a predefined
function, BTW) has static storage duration, and it's entirely
plausible that something external to the program could modify it.
In the original example, the volatile object was simply a parameter
to a small function, existing only for the duration of that program's
"that function's execution" presumably.
It's far less plausible that any external entity would
even know about it, let alone touch it. (Unless some compiler magic
causes the creation of a volatile object to make it visible to some
external entity, but that's a bit of a stretch.) In principle, if
it's declared volatile then it's volatile; in practice, it hardly
makes sense to apply volatile to a simple object with automatic
No one is saying that the original example made sense. It's purpose
(however unintentional) has been to start a discussion of volatile
automatic objects and, having thought about the notion, it seems to me
that it is not entirely daft. Daft, yes, but not entirely daft. Hence
my example about a garbage collector where an external agent might be
able to tell which stack objects are pointers (it would need some help
from the compiler, of course).
- Re: volatile Info
- From: Walter Banks
- Re: volatile Info
- Prev by Date: Re: How to increment array of pointers to strings
- Next by Date: Re: "claim", etc. (was Re: C Standard Regarding Null Pointer Dereferencing)
- Previous by thread: Re: volatile Info
- Next by thread: Re: volatile Info