optimization and volatile

dmr at alice.UUCP dmr at alice.UUCP
Fri Dec 23 18:03:37 AEST 1988


For the record, I don't recall any transformation made by the PDP-11
compiler or peephole optimizer that caused problems with device register
references. Perhaps someone else has an example?  I'll try it out.

To repeat myself from last year, I think it would
have been plausible for X3J11 to do without 'volatile,' but certainly
this would have required some words in the standard discussing the
permissible effects of varying levels of optimization, and probably
mandating compiler flags.  This is unpleasantly non-linguistic (but so
too is the difference between hosted and non-hosted environments).

It is certainly desirable that programs run fast, and optimization
techniques evidently aid this goal; it is also desirable that programs
mean what they seem to say.  Notions like device registers and
asynchronous access to data (interrupts or multitasking) introduce
serious conflicts between these goals, and the conflict needs to
be relieved somehow (even if not perfectly).

All in all, 'volatile' is not a bad compromise.  It trades additional
language complexity and necessarily fishy semantics against improved
visibility (both to the human and to the compiler) of the fishy parts.

		Dennis Ritchie
		research!dmr
		dmr at research.att.com



More information about the Comp.lang.c mailing list