C and real hardware

utzoo!decvax!cca!ima!n44a!dan utzoo!decvax!cca!ima!n44a!dan
Wed Apr 27 15:34:30 AEST 1983


	In C code such as device drivers, one often encounters code like:

	while (ADDR->c_reg&BUSY)
		;

	where one is testing bits of a hardware device register, and waiting
for a change.

	In there anything in the C specification which would prevent a good
(but obviously not perfect) optimizer from reading the value of the device
register just once, stuffing it into a CPU general purpose register and looping
on its value ?
	I have noticed that at least some of the 4xbsd makefiles seem to
purposely avoid the optimizer - is this sort of thing the reason ?
	Might not C benefit from some additional type (e.g. "unregister")
which would tell an optimizer what was up. I believe DEC's MicroPower Pascal has
a type called "volatile" which prevents this sort of thing.

					Dan Ts'o



More information about the Comp.lang.c mailing list