From: mark@cita.toronto.edu (Mark Bartelt)
Subject: Re: horrible "cc -O" bug (DU 3.2c)
Date: 1997/05/12 [thread overview]
Message-ID: <EA2EBs.Fo2@utcc.utoronto.ca> (raw)
In-Reply-To: 5l5i98$hbk$1@news.nyu.edu
[ Gerald A. Feldman ]
>> First of all, from looking at the code, it does not appear to be a code
>> generation bug at all. It is only a bug if the code beyond the && would
>> cause a side effect, such as invoke a function, modify a variable, or
>> cause an exception.
[ Roy Smith ]
>> That's like saying that if the code generated for "x = 3" actually assigns
>> the value 4 to x, it's only a bug if the value of x is used later in the
>> program.
As a parenthetical and somewhat off-topic aside, I'd leave *that* one for the
philosophers, as a code-generator analogue of "if a tree falls in a forest ..."
sort of question. I *have* encountered compilers which don't bother assigning
any value at all to a variable if they can determine with 100% certainty that
the variable is never used subsequent to the requested assignment.
However, to get back on-track ...
[ Roy Smith ]
>> The language semantics say that in "x && y", y is not evaluated unless x is
>> true. This lets you do things like "xp && *xp". Or "is_valid(foo) &&
>> get_value(foo)". Or "x < 3 && x++". Some of those may be ugly, but they
>> are legal, and all require that the part after the && not be evaluated if
>> the part before the && is false.
Roy is spot-on correct on this point. (Hey, I *have* to agree; I'm the one who
started this whole thread! ;-) When in doubt, consult scripture: K&R makes it
totally clear, when it says
Expressions connected by && or || are evaluated left to right,
and it is guaranteed that evaluation will stop as soon as the
truth or falsehood is known.
QED. Bug. Case closed.
Mark Bartelt 416/978-5619
Canadian Institute for mark@cita.utoronto.ca
Theoretical Astrophysics http://www.cita.utoronto.ca/~mark
"Sheep not busy being shorn are busy frying" -- Dylan, at a NZ lamb barbecue
[ singing "It's all right, ma (I'm only bleating)" ]
next prev parent reply other threads:[~1997-05-12 4:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-05-09 4:00 horrible "cc -O" bug (DU 3.2c) Mark Bartelt
1997-05-09 4:00 ` Jonathan Rozes
1997-05-09 4:00 ` John Hascall
1997-05-10 4:00 ` Gerald Feldman
1997-05-11 4:00 ` Roy Smith
1997-05-11 4:00 ` Gerald A. Feldman
1997-05-11 4:00 ` Roy Smith
1997-05-12 4:00 ` Jeff Sullivan USG
1997-05-12 4:00 ` Gerald A. Feldman
1997-05-12 4:00 ` Mark Bartelt [this message]
1997-05-12 4:00 ` Andy Isaacson
1997-05-12 4:00 ` John Reinitz
1997-05-13 4:00 ` Mark Bartelt
1997-05-12 4:00 ` Jeff Sullivan USG
1997-05-12 4:00 ` Peter Kocourek
1997-05-12 4:00 ` Bob Vickers
1997-05-11 4:00 ` Michael C. Grant
[not found] ` <5l7hap$7la@usenet.pa.dec.com>
1997-05-12 4:00 ` Gerald A. Feldman
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