Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!amdahl!nw From: nw@amdahl.uts.amdahl.com (Neal Weidenhofer) Newsgroups: comp.lang.c Subject: Re: volatile Message-ID: <27135@amdahl.uts.amdahl.com> Date: 8 Apr 88 17:28:30 GMT References: <12578@brl-adm.ARPA> <1988Mar25.172355.348@utzoo.uucp> <4269@ihlpf.ATT.COM> Organization: Amdahl Corporation, Sunnyvale CA Lines: 42 Summary: "Volatile" semantics say nothing about when an update takes place In article <4269@ihlpf.ATT.COM>, nevin1@ihlpf.ATT.COM (00704a-Liber) writes: > I've got a question on 'volatile'. In the following code fragment: > > /*...*/ > extern volatile int foo; > int bar; > int int_function(); > /*...*/ > bar = foo++ + int_function(); > /*...*/ > > how is foo incremented? Is the value saved when it is read for the > addition, the value 1 added to it, and stored back in foo? Is foo just > incremented whenever the compiler would normally increment a post-increment > non-volatile variable? Is this just an error that a compiler should flag. > I've looked in the standard for the answer and I can't find one. > -- > _ __ NEVIN J. LIBER ..!ihnp4!ihlpf!nevin1 (312) 510-6194 It's not an error but any of the other possibilities you list are valid. All that dpANS mandates of a conforming implementation in a case like this is that: At some time after the last sequence point before the beginning of the statement and before the sequence point at the end of the statement, the varaible foo is "read" once and "written" once (whatever this may mean for a specific implementation.) Or that the results of running the program are the same as they would be if this were true--the "as if" rule. (N.B. There are also lots of mandates about the arithmetic, etc. that I don't believe are relevant to your question.) Extra disclaimer: Even though I'm a member of the committee, I'm not a spokesperson for us. The above represents my understanding of our intent. The opinions expressed above are mine (but I'm willing to share.) Regards, Neal Weidenhofer It's not the earth ...{hplabs|ihnp4|ames|decwrl}!amdahl!nw The meek inherit, Amdahl Corporation It's the dirt. 1250 E. Arques Ave. (M/S 316) P. O. Box 3470 Sunnyvale, CA 94088-3470 (408)737-5007