From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1149ec,d055dd2f0172279a X-Google-Attributes: gid1149ec,public X-Google-Thread: fee84,d055dd2f0172279a X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1995-02-15 01:57:49 PST Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!udel!news.mathworks.com!newshost.marcam.com!charnel.ecst.csuchico.edu!olivea!rahul.net!a2i!rfg.a2i!rfg From: "Ronald F. Guilmette" Newsgroups: comp.unix.osf.osf1,comp.std.c Subject: Re: Alpha compiler bug Date: 15 Feb 1995 09:57:49 GMT Organization: a2i network Message-ID: <3hsj6t$ro1@hustle.rahul.net> References: <3houb5$8cr@vixen.cso.uiuc.edu> NNTP-Posting-Host: bolero.rahul.net NNTP-Posting-User: rfg Xref: nntp.gmd.de comp.unix.osf.osf1:7673 comp.std.c:9792 In article , David Gelhar wrote: >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. Yep. And this was confirmed by X3J11/WG14 in their response to Defect Report number 117 (which, not coincidently, asked about a very very similar expression). >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. I've always been mildly troubled about the loose way that the committee used the word ``between'' when speaking of sequence points. In the vast majority of cases in the standard, the word ``between'' means ``textually between'', whereas in the case of sequence points, any use of the word ``between'' really means ``between, in time''. This important point got lost someplace during the drafting of the standard. >The comp.std.c lawyers may be able to give a more definitive chapter & verse >answer (Note the crossposting!) Consider it done. (I happen to have been the one who filed DR #117, and I was present and accounted for when the response was drafted and approved, so I guess that I can count myself as among the ``language lawyers'' of record with regard to this question.) -- -- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting ------------------- ---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ---- -------------------------------------------- Suites and Bullet-Proof Shoes -