Re: volatile Info



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:

int minutes(void)
{
extern volatile int clock;
return clock/60;
}

The scope is, if anything, even shorter but this seems like a normal use
of volatile.
[...]

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
appears not.

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
execution.

"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
storage duration.

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).

--
Ben.
.



Relevant Pages

  • Re: volatile Info
    ... The volatile variable in the example has a very limited scope ... extern volatile int clock; ... argument in square is copied as part of the call ...
    (comp.lang.c)
  • Re: volatile Info
    ... extern volatile int clock; ... The scope is, if anything, even shorter but this seems like a normal use ... the volatile object was simply a parameter ... It's far less plausible that any external entity would ...
    (comp.lang.c)
  • Re: volatile Info
    ... The volatile variable in the example has a very limited scope ... argument in square is copied as part of the call ... I don't think that volatile objects have to be modified using their ...
    (comp.lang.c)
  • Re: xotcl vs incr tcl
    ... you are not restricted to its creation ... What I'd like to see from these "volatile" schemes is for there to be ... a way to say "I want to expand the scope of the volatility". ...
    (comp.lang.tcl)
  • Re: Problems with Optimization !!
    ... without optimization but fails when otimized. ... extern volatile int  Counter; ... Prevent the reordering of instructions in the function ...
    (comp.os.vxworks)