A different view of volatile

der Mouse mouse at mcgill-vision.UUCP
Mon May 16 17:43:09 AEST 1988


In article <178 at wyse.wyse.com>, mikew at wyse.wyse.com writes:
> It seems that volatile is ill-defined when combined with operators
> that operate in-place.  [suggestion:] [S]tate that conforming
> programs can't have a volatile variable that is on boths sides of an
> equal sign, volatile variables can't be used on the left hand side of
> [the (op)= operators] and volatiles can't be used at all with [++ and
> --].

> Example:  [edited]

> volatile int a;  int c;
> a=a;		/* illegal */
> a=a+c;		/* illegal */
> a+=c;		/* illegal */

I would argue that none of the above are at all hazy.  In each case, I
would claim that the result is exactly equivalent to the result
obtained by using a temporary.  For example, we can consider a+=c to be
identical to a=a+c (a is a simple variable, remember).  So the second
and third are really the same.  Then, I would say that

a = <expression>;

is identical to

{ /* not volatile */ int temp; temp = <expression>; a = temp; }

On some machines, this may mean that a+=c must compile to different
code depending on whether a is volatile.  (For example, the VAX addl2
instruction might not be usable, depending on exactly how it works.)

					der Mouse

			uucp: mouse at mcgill-vision.uucp
			arpa: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list