ANSI C, optimization, `volatile' declarations

M. J. Shannon, Jr. mjs at rabbit.UUCP
Mon Oct 15 12:11:14 AEST 1984


<Eat this, Bug!>

> > [Compiler is optimizing out a wait-for-hardware-done loop.]
> > ...
> > 1.  Was this legal code generation?
> > 2.  Note that this compiler did "simple" optimizations as part of the code
> > 	generation. Is this legal?
> 
> As to whether it's legal by K&R, the only answer is "mumble".  This
> thorny issue was never addressed in the old days.  The draft ANSI standard
> has a "volatile" declaration that you can use to tell the compiler "don't
> get tricky with this variable, it may change underfoot".

First, I'd like to point out that the name of the standards organization
is ANSI: American National Standards Institute.  The name is unrelated to
the name of the character set most of us are using (ASCII: American
Standard Code for Information Interchange).  Now, with that out of the
way....

Ok, given the `volatile' keyword, what are its semantics?  If (on System V)
I have pointers into memory that is shared by other processes, must I
declare them `volatile struct foo *' and have the compiler deduce that all
members of such a structure are volatile (my opinion of correct behavior)?
Further, if the structure so referenced has pointers in it, are they
assumed to be volatile or non-volatile?  If my program manages linked lists
in shared memory, must the forward and backward pointers also be declared
volatile?  If so, this means that I may suffer from non-optimization of
linked lists (identically declared) in non-shared memory.  Volatility
declarations are very tricky in a language such as C!

Is a current draft available (sorry, I haven't been following this
discussion due to (what seems to me to be) an inordinate amount of
drivel)?  If so, how may I obtain it?
-- 
	Marty Shannon
UUCP:	{alice,rabbit,research}!mjs
	(rabbit is soon to die.  Does this mean alice is pregnant?  Yup!)
Phone:	201-582-3199



More information about the Comp.lang.c mailing list