Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!rutgers!iuvax!pur-ee!uiucdcs!uiucdcsm!robison From: robison@uiucdcsm.cs.uiuc.edu Newsgroups: comp.lang.c Subject: hack to fake volatile Message-ID: <4700010@uiucdcsm> Date: 30 Mar 88 23:31:00 GMT Lines: 24 Nf-ID: #N:uiucdcsm:4700010:000:837 Nf-From: uiucdcsm.cs.uiuc.edu!robison Mar 30 17:31:00 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@UIUC.CSNET UUCP: {ihnp4,pur-ee,convex}!uiucdcs!robison ARPA: robison@B.CS.UIUC.EDU (robison@UIUC.ARPA)