Volatile is Necessary

David Wolverton daw at houxs.UUCP
Fri Apr 1 00:40:45 AEST 1988


In article <77200028 at uiucdcsp>, gillies at uiucdcsp.cs.uiuc.edu writes:
[stuff deleted about multiprocessing]
> THE ONLY reason to keep it [volatile] in the language is if you can argue it's
> important for uniprocessing....

[I think this discussion is getting sidetracked.  The question is whether
the volatile type qualifier should have been included in the ANSI C (draft)
standard.]

As an implementor of an optimizer, I rejoiced when I saw that the committee
had added 'volatile' to the language.

The point of volatile is that 98% of a program's variables (and 99% in portable
programs) will *not* be qualified with 'volatile', which allows optimizers
to make assumptions about the optimizations which can be applied to a variable.
Without 'volatile', the optimizer has to use a pessimistic assumption about
the variables so that it won't stomp on the 1-5% of the variables which care
about it!

'volatile' is *not* present to help any specific thing like interrupt handlers,
multiprocessing, shared memory, etc.  Rather, it helps them all, because its
*absence* in "normal" code tells the optimizer that none of those funky things
are happening behind its back.  That is why 'volatile' is in the language.

Dave Wolverton
AT&T



More information about the Comp.lang.c mailing list