From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,ae6d7754224e7cfb X-Google-Attributes: gid1164f8,public X-Google-Thread: fee84,ae6d7754224e7cfb X-Google-Attributes: gidfee84,public From: mark@cita.toronto.edu (Mark Bartelt) Subject: Re: horrible "cc -O" bug (DU 3.2c) Date: 1997/05/12 Message-ID: #1/1 X-Deja-AN: 241098530 Sender: nntp@utcc.utoronto.ca (News) X-Nntp-Posting-Host: rorqual.cita.utoronto.ca References: <5kvqsu$18d$1@news.iastate.edu> <5l33qi$6fg$1@news.nyu.edu> <33763487.7250953E@highway1.com> <5l5i98$hbk$1@news.nyu.edu> Organization: Canadian Institute for Theoretical Astrophysics Reply-To: mark@cita.utoronto.ca Newsgroups: comp.unix.osf.osf1,comp.sys.dec [ 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)" ]