ANSII C, optimization, and "hardware registers"
Guy Harris
guy at rlgvax.UUCP
Wed Oct 17 08:29:41 AEST 1984
> I have just run into a really fun thing with an optimizer. ...
> (Discussion of optimization that doesn't work on "volatile" locations
> like device registers)
>
> Now here is the question:
> 1. Was this legal code generation?
> 2. Note that this compiler did "simple" optimizations as part of the code
> generation. Is this legal?
I'd say "yes" to both questions. (BTW, if this was code for a VAX-11, there's
an undocumented "-i" flag to "c2" which turns off these optimizations; the
4.2BSD Makefile uses it for anything declared as "device-driver" in the
"files" or "files.vax" file.)
> I know of several ways around this, but I thought that it should be addressed
> by the ANSII standard.
It is; there's a pseudo-storage-class called "volatile" which says "this
is subject to change without notice, so don't be clever and optimize references
to it." This is actually useful in for things other than device registers,
given that the UNIX kernel has data within it shared by multiple processes,
and that several versions of UNIX, as well as other OSes, support data shared
between user processes.
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy
More information about the Comp.lang.c
mailing list