hack to fake volatile

robison at uiucdcsb.cs.uiuc.edu robison at uiucdcsb.cs.uiuc.edu
Mon Apr 4 07:23:00 AEST 1988



Scott Daniels (daniels at teklds.UUCP) pointed out a bug in my original hack
to fake "volatile".  There are situations involving writes-only which an 
"optimizer" may incorrectly transform.  

One needs a call to "Munge" in both the read and write routines to
"flush the caches", so to speak.

	int _X;		/* local to WriteX and ReadX */

	#define WriteX(a) (_X=a, Munge(&_X))	/* Munge is a secret no-op */
	#define ReadX     (Munge(&_X), _X)

I'm not sure how to formally verify this hack.  I suppose one could argue
that any asynchronous writes and reads could be simulated by the Munge calls,
and therefore the optimizer must keep its paws off.  But this is far from 
a convincing argument.

Arch D. Robison
University of Illinois at Urbana-Champaign
	
CSNET: robison at UIUC.CSNET
UUCP: {ihnp4,pur-ee,convex}!uiucdcs!robison
ARPA: robison at B.CS.UIUC.EDU (robison at UIUC.ARPA)



More information about the Comp.lang.c mailing list