volatile

Neal Weidenhofer nw at amdahl.uts.amdahl.com
Sat Apr 9 03:28:30 AEST 1988


In article <4269 at ihlpf.ATT.COM>, nevin1 at 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



More information about the Comp.lang.c mailing list