From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1149ec,d055dd2f0172279a,start X-Google-Attributes: gid1149ec,public X-Google-Thread: fee84,d055dd2f0172279a,start X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1995-02-14 00:01:44 PST Path: nntp.gmd.de!newsserver.jvnc.net!howland.reston.ans.net!news.moneng.mei.com!uwm.edu!news.alpha.net!news.mathworks.com!newshost.marcam.com!charnel.ecst.csuchico.edu!olivea!news.bu.edu!dartvax.dartmouth.edu!lemitar.dartmouth.edu!user From: David.Gelhar@Dartmouth.EDU (David Gelhar) Newsgroups: comp.unix.osf.osf1,comp.std.c Subject: Re: Alpha compiler bug Date: Tue, 14 Feb 1995 03:01:44 -0500 Organization: Dartmouth College, Hanover, NH, USA Message-ID: References: <3houb5$8cr@vixen.cso.uiuc.edu> NNTP-Posting-Host: lemitar.dartmouth.edu Xref: nntp.gmd.de comp.unix.osf.osf1:7634 comp.std.c:9773 In article <3houb5$8cr@vixen.cso.uiuc.edu>, peltz@cerl.uiuc.edu (Steve Peltz) wrote: > DEC OSF/1 V3.0 (Rev. 347) > > Expression such as: > (temp = a + b, temp * (a + b)) + (temp = c + d, temp * (c + d)) > > do not compile correctly with optimization level greater than 0. It uses > the same value of temp for both multiplies, instead of correctly handling > the parenthesized comma separated expressions. > > E.g. a=1, b=2, c=3, d=4, the correct answer is 58; the incorrect answer > given with -O1 is 70. > > Am I confused and this is actually undefined behavior for ANSI, or is this > a compiler bug? Is there a patch? Looks like undefined behavior to me. Within the subexpressions there is a sequence point (comma), so we know "temp = a + b" is evaluated before "temp * (a + b)" (and so forth). As far as I can tell, though, there's no sequence point between "temp = a + b" and "temp = c + d", so we don't know anything about the order of evaluation of the two assignments. Assigning to the same variable twice without an intervening sequence point means the results are undefined. The comp.std.c lawyers may be able to give a more definitive chapter & verse answer (Note the crossposting!) -- David Gelhar david.gelhar@dartmouth.edu