Path: utzoo!attcan!uunet!husc6!think!ames!killer!pollux!dalsqnt!usl!ralph!pja From: pja@ralph.UUCP (Pete Alleman) Newsgroups: comp.lang.c Subject: Re: Volatile is stupid Keywords: Compilers don't know all! Message-ID: <278@ralph.UUCP> Date: 18 Jun 88 17:11:54 GMT References: <11837@mimsy.UUCP> <225800035@uxe.cso.uiuc.edu> <5800@aw.sei.cmu.edu> Reply-To: pja@ralph.UUCP (Pete Alleman) Distribution: na Lines: 39 In article <5800@aw.sei.cmu.edu> firth@bd.sei.cmu.edu.UUCP (Robert Firth) writes: >Would it not be far simpler, and far safer, for the compiler to read >a single "target memory definition file", or similar, that says > > 00000000..0003ffff is ROM > 00040000..00ffffff is RAM > fffffeeb is volatile > >and so on, and so on? If anyone changes the physical target, they edit >the target memory definition file. The complier simply reads this file >whenever it compiles a program, and does the right thing. If you are > >Not only does this work, it is amenable to decent verification, management, >configuration control, and maintenance. "Volatile" is a hacker's answer. The compiler generally DOES NOT KNOW the address being accessed. The only time the compiler can know an absolute address is when that address is an int being typecast to a pointer and then dereferenced. As an example suppose I were to write this routine: dev_wait (csr) volatile int *csr; { /* wait for the device to complete some operation */ while (*csr & DEVBUSY) /* So this is in the kernel, reasonable example */ sleep (csr, PRI); } How could the compiler possibly know that the pointer passed at runtime might point to a volatile location (without the keyword)?? The compiler generally works with symbolic addresses. The LINKER assigns values to those symbols and puts the actual numbers in the proper locations in the code. -- Pete Alleman ralph!pja or digitran!pja