volatile

der Mouse mouse at mcgill-vision.UUCP
Wed May 18 17:36:32 AEST 1988


In article <526 at wsccs.UUCP>, terry at wsccs.UUCP (Every system needs one) writes:
> All I'm saying, again and again and again, is that the compiler
> writer, not the compiler user should bear the burden of matching the
> language to the architecture.  I have agreed before that volitile is
> OK for DMA where the user prefers to use a buzz-loop instead of an
> interrupt.  Say a message passing operating system.

Or for emptying a serial line card silo into the user's buffer....what
happens to

for (count=sludevice->wcr;count>0;count--)
 { *bufptr++ = sludevice->recvbuf;
 }

when the optimizer rewrites it to

temp = sludevice->recvbuf;
for (count=sludevice->wcr;count>0;count--)
 { *bufptr++ = temp;
 }

Or are you intending to prohibit such an optimization altogether?  Then
sorry, you'll be left in the dust.  The compiler simply doesn't have
enough information to guess whether sludevice points to a memory-mapped
device or not!

> I don't believe in impossible; just very very hard and requiring
> intelligent thought.

Ah, you expect the compiler to notice that the file it's compiling
happens to look something like a device driver, this struct pointer
variable name ends in "device", therefore it should be treated as
volatile?  Good luck trying to convince your compiler vendor.

>> Compiler technology is getting really good, and we need a way to
>> tell the optimisers that strange things can happen.
> If it's sooooo advanced, it could determine volatility (or aliasing)
> without me having to tell it.  This is my entire point.  If it isn't
> that advanced, it should either quit pretending or be fixed.

There's an intermediate stage.  Compiler technology is good enough to
do some serious optimizations if it's told what's volatile.  It is not
good enough to figure out what's volatile and what isn't (I don't
expect it to be, either, not before we have serious (Turing-capable)
artifical intelligence).  Since joe programmer writing matrix inversion
routines (say) can completely ignore volatile and get all the
optimizations, we put up with making the few who write code that uses
signals or memory-mapped devices or shared memory or other things that
more-or-less require volatile use volatile.

					der Mouse

			uucp: mouse at mcgill-vision.uucp
			arpa: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list