Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!columbia!caip!nike!cad!ucbvax!decvax!tektronix!teklds!dadla!tekla!dant From: dant@tekla.UUCP (Dan Tilque) Newsgroups: net.lang.c Subject: op= construction Message-ID: <606@tekla.UUCP> Date: Tue, 10-Jun-86 20:08:13 EDT Article-I.D.: tekla.606 Posted: Tue Jun 10 20:08:13 1986 Date-Received: Sat, 14-Jun-86 06:30:21 EDT Organization: Tektronix, Inc., Beaverton, OR Lines: 32 >From: cgw@mruxe.UUCP (C Waldman) > Quick question- > > In a loop, an array element is incremented, then the array index > is advanced to the next element. I recently coded this with > > .... > total[i++] += f; > .... > > After a couple of "Memory fault- core dumped" messages, I realized > that i is getting incremented twice. I broke it into two lines and > everything was ok, but I'm wondering why this construction doesn't > work. Your compiler seems to have a bug in the way it evaluates total[i++]. The gospel according to K&R (p. 191): The behavior of an expression of the form E1 op= E2 may be inferred by taking it as equivalent to E1 = E1 op (E2); however, E1 is evaluated only once. Your compiler seems to be evaluating total[i++] twice, once for the left side of the =, and once for the right. I ran a simple test on our compiler (cc) and it seems to work right. ========================================================================== Dan Tilque Googol in, Googolplex out. (tektronix!dadla!dant) ==========================================================================