Path: utzoo!attcan!uunet!husc6!purdue!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: volatile Message-ID: <11547@mimsy.UUCP> Date: 18 May 88 02:58:25 GMT References: <20345@pyramid.pyramid.com> <502@wsccs.UUCP> <51431@sun.uucp> <390@attila.weitek.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 39 In article <390@attila.weitek.UUCP> mahar@weitek.UUCP (Mike Mahar) writes: >Consider the following C program. Remember this is All the information you >get. The actual addresses of variables are unknown. Any other modules >are compiled separately. What you see is all you get. You have made what can be called an unreasonable restriction. Why is the compiler not able to see the other modules? The only possible answers are `they do not exist' or `the compiler is not smart enough'. If they do not exist, there is no problem; if they are later created, the compiler is expected to be smart enough to see them then. (All this requires is that you defer code generation until after the link step.) [compressed, and with the bug fixed:] >char fifo; >buf_fill(char *buffer, int cnt) { > int i; > for (i = 0; i < cnt; i++) *buffer++ = fifo; >} If I as a reader saw this, I might be tempted to rewrite it thus: register int i = cnt, fillbyte = fifo; while (--i >= 0) *buffer++ = fillbyte; The compiler may be able to tell whether `fifo' is volatile, but given the lack of such a declaration or a comment or `#pragma' or any other clue, *I* may not, so please use something like volatile char fifo; or char fifo; /* DANGER : i/o space : volatile : DANGER */ or char fifo; #pragma volatile fifo; -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris