volatile (in comp.lang.c)

Peter J Desnoyers peter at athena.mit.edu
Fri Jun 3 12:06:03 AEST 1988


In article <4922 at ihlpf.ATT.COM> nevin1 at ihlpf.UUCP (00704a-Liber,N.J.) writes:
>
>C itself does not guarantee that access to any particular data type,
>including char, is atomic.  My question is:  is there *any* use for 'volatile'
>which does not require 'atomicity' at some level?  If not, then 'volatile'
>doesn't really fix any of the problems we have without it.
>
I had always thought that the typical application of |volatile| would be
something like:

	volatile char * z80sio_rr0 = io1 + 0; /* is this declared */
	volatile char * z80sio_rr1 = io1 + 1; /* correctly? */
	...

or the non-portable, but no doubt common

        union z80sio {
	    struct sio_r {
		char * rr0, * rr1, * rr2;
	    } read;
	    struct sio_w {
		char * ww0, * ww1, ...;
	    } write;
	}

(substitute your favorite - i.e. least hated - comm chip, peripheral,
or what have you.)

When developing code for a development platform such as a Unix box,
code like this only has to be written once, when the operating system
is written. When developing code for an embedded system (what people
then use those Unix boxes to develop :-) code like this is written
once, but that's all the code there is.

				Peter Desnoyers
				peter at athena.mit.edu



More information about the Comp.lang.c mailing list