Path: utzoo!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mailrus!nrl-cmf!ames!umd5!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: volatile Message-ID: <7915@brl-smoke.ARPA> Date: 18 May 88 14:18:31 GMT References: <20345@pyramid.pyramid.com> <502@wsccs.UUCP> <51431@sun.uucp> <526@wsccs.UUCP> <390@attila.weitek.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 35 In article <390@attila.weitek.UUCP> mahar@attila.UUCP (Mike Mahar) writes: >char fifo; >buf_fill(buffer,cnt) > char *buffer; > int cnt; > { > int i; > for( i = 0; i < cnt; i++) > *buffer++ = fifo; ^ MISSING * ADDED > } >Question: Is it safe to compile the preceding routine like this: > movb _fifo,d2 #pre-load fifo >L1: In this particular case it is safe to pre-load `fifo' before the loop. (It would be disallowed if `fifo' were declared "volatile".) However, if the code were changed to char fifo[3]; buf_fill(buffer,cnt) char *buffer; int cnt; { int i; for( i = 0; i < cnt; i++) *buffer++ = fifo[1]; } Then it would NOT be permitted to pre-load fifo[0], because the function could be invoked as buf_fill(fifo,3); and the generated code must handle the aliasing correctly.