🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1938

Re: A question on volatile accesses

#1938
From: Chris Torek
Date: Sun, 04 Nov 1990 22:03
29 lines
1651 bytes
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
Technical Details
Message-ID: <27427@mimsy.umd.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!mimsy!chris
References: <2388@lupine.NCD.COM> <27407@mimsy.umd.edu> <2402@lupine.NCD.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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