Volatile is stupid

Pete Alleman pja at ralph.UUCP
Sun Jun 19 03:11:54 AEST 1988


In article <5800 at aw.sei.cmu.edu> firth at 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



More information about the Comp.lang.c mailing list