Volatile (was Re: observability)

Barry Margolin barmar at think.COM
Fri Sep 8 07:17:23 AEST 1989


I think that I may have figured out what the earlier poster meant when
he said that the effects of "volatile" aren't observable.

When the volatile modifier is added to a variable, various constraints
are placed on the implementation regarding the compilation of accesses
to that variable.  Conversely, removing the volatile modifier simply
makes some operations implementation-dependent; I don't think it ever
adds any constraints.

Therefore, an implementation that treats all variables as if they were
volatile would be valid.  In such an implementation, adding and
removing volatile modifiers would have no effect on the observable
behavior of the program.

An implementation could also randomly treat non-volatile variables as
if they were volatile.  During testing, the randomness might cause
everything to work as the programmer wants.

The point is that there's no reliable way to test whether the volatile
modifier is ignored by an implementation.  If a pair of programs which
differr only in the use of volatile have the same observable effects,
it could be accidental or it could be because it ignores the modifier.


Barry Margolin
Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.std.c mailing list