Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: "Stefan Monnier" <monnier@di.epfl.ch>
Subject: Re: Alpha compiler bug
Date: 14 Feb 1995 14:21:11 GMT	[thread overview]
Message-ID: <3hqe8n$6pa@info.epfl.ch> (raw)
In-Reply-To: 3houb5$8cr@vixen.cso.uiuc.edu

In article <3houb5$8cr@vixen.cso.uiuc.edu>,
Steve Peltz <peltz@cerl.uiuc.edu> 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 --
--------------------------------------------------------------------


  parent reply	other threads:[~1995-02-14 14:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3houb5$8cr@vixen.cso.uiuc.edu>
1995-02-14  8:01 ` Alpha compiler bug David Gelhar
1995-02-15  9:57   ` Ronald F. Guilmette
1995-02-14 14:21 ` Stefan Monnier [this message]
1995-02-14 17:15 ` Peter da Silva
1995-02-14 19:08   ` Steve Peltz
1995-02-16 17:50     ` Peter da Silva
1995-02-18 17:53       ` Dan Pop
1995-02-14 19:45 ` Dave Hill
1995-02-21 17:37   ` HP LJ4M on OSF/3 Tadhg McCarthy
1995-02-21 17:41   ` PCL files on a HP4M printer Tadhg McCarthy
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox