Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!thumper!ulysses!ucbvax!bloom-beacon!athena.mit.edu!peter From: peter@athena.mit.edu (Peter J Desnoyers) Newsgroups: comp.lang.c Subject: Re: volatile (in comp.lang.c) Message-ID: <5607@bloom-beacon.MIT.EDU> Date: 3 Jun 88 02:06:03 GMT References: <20345@pyramid.pyramid.com> <833@mcdsun.UUCP> <1988May23.003847.1114@utzoo.uucp> <1078@micomvax.UUCP> <4922@ihlpf.ATT.COM> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: peter@athena.mit.edu (Peter J Desnoyers) Organization: Massachusetts Institute of Technology Lines: 36 In article <4922@ihlpf.ATT.COM> nevin1@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@athena.mit.edu