A question on volatile accesses
Chris Torek
chris at mimsy.umd.edu
Mon Nov 5 09:03:20 AEST 1990
In article <27407 at mimsy.umd.edu> I wrote:
> i = *ip; ip++; i *= *ip;
>could be computed as
> x = ip[1]; y = ip[0]; i = x * y; ip += 2;
Oops, that should be `ip += 1' (or ip++ or ++ip).
In article <2402 at lupine.NCD.COM> rfg at NCD.COM (Ron Guilmette) writes
further:
>Thus, the pre-increment occurs *after* the indirection.
>Thus, the function returns `1' and not `2'.
>So is this a violation of the ANSI standard or what?
Yes, it is incorrect (and the presence or absence of `volatile' is
irrelevant to this answer). `i = *++ip' must indirect through the
value that results from the increment, even though the increment itself
need not occur before the indirection. (Consider a machine with
several functional units, which might handle `i = *++ip' as:
tell unit 0: `read memory at 4(r9)'
tell unit 1: `compute r9 + 4'
wait for unit 0 to release r9 (indicating it has saved the old value)
tell unit 1: `store result in r9'
tell unit 0: `store result in r10'
in which the increment and the fetch happen `almost simultaneously'.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.std.c
mailing list