A different view of volatile

00704a-Liber nevin1 at ihlpf.ATT.COM
Fri May 6 03:09:21 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.  A way of alleviating this problem would
>be to state 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 following 
>operators: +=, -=, *=, /=, |=, &=, and volatiles can't be used at all
>with the following operators: ++, --.

I was going to propose this myself!!  I have a problem with one of your
examples, though.

>volatile int a,b;
>a=b;		/* legal */

This type of assignment should be illegal, since

>a=a;		/* illegal */

is illegal.  Suppose the declaration was:

int	foo(bar1, bar2)
volatile int	*bar1, *bar2;
*bar1 = *bar2;

There may be no way, with static checking, to determine if bar1 and bar2
are the same or different.  At most one variable of type volatile is
allowed to appear in any statement (except for function arguments).

Also, volatile variables should probably be limited to types which only
require one machine instruction to load them, such as char, int, and *void (ie,
structs should not be allowed to be declared volatile), and arrays made up
of these types.
-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah



More information about the Comp.lang.c mailing list