From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,d055dd2f0172279a X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1995-02-14 06:21:11 PST Path: nntp.gmd.de!newsserver.jvnc.net!howland.reston.ans.net!math.ohio-state.edu!jussieu.fr!univ-lyon1.fr!swidir.switch.ch!epflnews!monnier From: "Stefan Monnier" Newsgroups: comp.unix.osf.osf1 Subject: Re: Alpha compiler bug Date: 14 Feb 1995 14:21:11 GMT Organization: Ecole Polytechnique Federale de Lausanne Message-ID: <3hqe8n$6pa@info.epfl.ch> References: <3houb5$8cr@vixen.cso.uiuc.edu> NNTP-Posting-Host: didec26.epfl.ch Originator: monnier@didec26.epfl.ch In article <3houb5$8cr@vixen.cso.uiuc.edu>, Steve Peltz wrote: ] 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? As far as I know, ANSI C doesn't specify any evaluation order in expression. Of course, the comma operator specifies a sequential order. But basically, the constraints are: temp = a + b before temp * (a + b) temp = c + d before temp * (c + d)) but that's all. So, it seems totally correct to rewrite the thing into: (temp = a + b, /* junked cause useless */ temp = c + d, (temp * (a + b)) + (temp * (c + d))) Stefan -- -------------------------------------------------------------------- -- Suicidez-vous jeune, vous profiterez plus longtemps de la mort -- --------------------------------------------------------------------