volatile

Greg Limes limes at sun.uucp
Sat Apr 30 13:53:05 AEST 1988


In article <502 at wsccs.UUCP> terry at wsccs.UUCP (Every system needs one) writes:
[previous junk removed for brevity]
>	Yes, but why is
>		volitile int foo;
>	better than
>		int foo;	/* VOLITILE*/
>	Except for the optimizer?

The first not only documents for the user that "foo" may be changed
outside the expected flow of control of the program (i.e. by hardware
or by a signal handler), but making it a part of the language forces
optimiser designers to leave open this trapdoor. It also standardises
where they will put the trapdoor, if/when they realize that programmers
need to be able to break out of the dreaded
	while (!signal_caught);
loops ... try running the previous line through the SunOS 4.0 compiler
at any optimisation level higher than about, say, -O1 ...

Compiler technology is getting really good, and we need a way to tell
the optimisers that strange things can happen. Frankly, I need volatile
so I can let the good optimisations rip on my code, without breaking
the communcation lines between mainline and interrupt-level; without
volatile, I am forced to miss the whole boat. Those of you who do not
want volatile, fine; ignore it when you see it, do not use it, and
compile with your optimisers lobotmized. I want to use all the nifty
stuff they jammed into "-O4".
-- 
   Greg Limes [limes at sun.com]				frames to /dev/fb



More information about the Comp.lang.c mailing list