hack to fake volatile
robison at uiucdcsm.cs.uiuc.edu
robison at uiucdcsm.cs.uiuc.edu
Thu Mar 31 09:31:00 AEST 1988
I came in late on the ``volatile'' argument, but the following hack
would seem to work without adding anything to the language.
The hack may be expressed as:
``Chain the optimizer's paws by encapsulating the volatile variable''
We declare the variable and two functions for accessing it:
int _X; /* local to WriteX and ReadX */
#define WriteX(a) (_X = a)
#define ReadX (Munge(&_X), _X)
The function ``Munge'' would be in a library and be implemented as a no-op,
but not known to the optimizer! Therefore the optimizer must invalidate
any copies of X in registers, as Munge could potentially (on Friday the
13's with a full moons) alter X.
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