Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!apollo!wanginst!mckeeman From: mckeeman@wanginst.UUCP Newsgroups: comp.lang.c Subject: Re: C and restraints on optimization Message-ID: <1007@wanginst.EDU> Date: Mon, 13-Apr-87 15:21:00 EST Article-I.D.: wanginst.1007 Posted: Mon Apr 13 15:21:00 1987 Date-Received: Sat, 18-Apr-87 08:28:42 EST References: <15958@sun.uucp> <5716@brl-smoke.ARPA> <14680@cca.CCA.COM> <6264@mimsy.UUCP> Organization: Wang Institute Lines: 48 Summary: the semantics of volatile & optimization Chris Torek writes: >Here is a question: Which of those problems are sidestepped by >volatile variables?... >Just what does `volatile' *do* in a compiler? What are the precise >semantics of volatile variables? If a volatile variable is just >one whose value can never be assumed from context, a compiler could >eliminate `dead' stores, so this definition is clearly wrong: > > volatile v; > v=0; v=1; Bill McKeeman (me) responds: I worry that volatile, designed to deal with asynchronous processes, is accidentally picking up some sequential access semantics baggage. The relevant paragraph from x3j11 is: 3.5.2.4 const and volatile The properties associated with the const and volatile type specifiers are meaningful only for expressions that are lvalues.... and ...Therefore any expression referring to such an object [volatile] shall be evaluated strictly according to the sequence rules of the abstract machine... That is pretty handy for those who want to keep the optimizer at bay. I interpret it to mean that both v=0; and v=1; must be executed in sequence in Torek's example above. A cast (volatile) can only be applied to an lvalue. I interpret this to mean that as a compiler writer, I am obligated to flag Torek's suggestion: #define h_bar ((volatile double) (6.626e-34 / 2 / PI)) under the present rules. QUESTION: Do we want to use volatile variables as a (subtle) way to indicate that our expressions are not to be optimized? Would this be more intuitive and transparent than ignored parentheses and unary +? -- W. M. McKeeman mckeeman@WangInst Wang Institute decvax!wanginst!mckeeman Tyngsboro MA 01879