Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.std.c Subject: Re: A question on volatile accesses Message-ID: <27427@mimsy.umd.edu> Date: 4 Nov 90 22:03:20 GMT References: <2388@lupine.NCD.COM> <27407@mimsy.umd.edu> <2402@lupine.NCD.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 29 In article <27407@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@lupine.NCD.COM> rfg@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@cs.umd.edu Path: uunet!mimsy!chris