Optimization (was Re: volatile)

Tom Neff tneff at atpal.UUCP
Tue Apr 26 08:48:34 AEST 1988


In article <895 at cresswell.quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
> ... [volatile] shouldn't be a #pragma because #pragma isn't supposed to
>change what anything _means_.  

I don't see volatile as changing what anything means, except to the optimizer.
Forbidding the code generator to cache a variable's contents should have
no effect on a program's behavior with 'classic' variables like counters in
ordinary RAM.  Indeed, in a compiler with full control over optimization,
setting a /NOOPTIMIZE switch ought to make volatile effectively a no-op,
since the elementary optimization of cacheing values within an expression,
for instance, would be turned off and the code would in fact go "to the
metal" every time a variable was referenced -- which is all volatile is
trying to do.  My claim is that volatile essentially says nothing
about a program except what's legal for the optimizer to play with -- thus 
#pragma is appropriate.  However I will not kick if it stays a keyword, as
I would have with the late unlamented noalias, simply because it would be
unnecessary to sprinkle new alien syntax into the familiar library header
files -- only those who need it would ever have to see it.


-- 
Tom Neff			UUCP: ...uunet!pwcmrd!skipnyc!atpal!tneff
	"None of your toys	CIS: 76556,2536		MCI: TNEFF
	 will function..."	GEnie: TOMNEFF		BIX: are you kidding?



More information about the Comp.lang.c mailing list