volatile
Doug Gwyn
gwyn at brl-smoke.ARPA
Thu May 19 00:18:31 AEST 1988
In article <390 at attila.weitek.UUCP> mahar at 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.
More information about the Comp.lang.c
mailing list