volatile

00704a-Liber nevin1 at ihlpf.ATT.COM
Thu Mar 31 11:33:29 AEST 1988


In article <9176 at tut.cis.ohio-state.edu> lvc at tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes:
|I might not understand volatile correctly but this might also be an
|example:
|
|	volatile int customer_changeable_var = 0;
|
|	main( )
|		...
|
|	if (customer_chageable_var != 0)
|	{
|		...
|	}
|
|If the volatile were dropped off, the compiler would be free to
|optimize out the "impossible" code.

The compiler would *not* be free to optimize out this code!!  Because
customer_changeable_var is EXTERNAL to main(), this optimization cannot
occur.  The fact that it is declared 'volatile' is irrelevant (unless you
are saying that the customer should be able to change the variable directly
by toggling a hardwired switch which is directly mapped to the memory
location at which customer_changeable_var is stored.  But this case is
non-portable, and the previously posted arguments apply).
-- 
 _ __			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