Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: ANSII C, optimization, and "hardware registers" Message-ID: <203@rlgvax.UUCP> Date: Tue, 16-Oct-84 18:29:41 EDT Article-I.D.: rlgvax.203 Posted: Tue Oct 16 18:29:41 1984 Date-Received: Thu, 18-Oct-84 00:45:06 EDT References: <1538@wateng.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 26 > 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