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: adisaacs@mtu.edu (Andy Isaacson) Subject: Re: horrible "cc -O" bug (DU 3.2c) Date: 1997/05/12 Message-ID: #1/1 X-Deja-AN: 241222585 References: <5kvqsu$18d$1@news.iastate.edu> <5l33qi$6fg$1@news.nyu.edu> <33763487.7250953E@highway1.com> <5l5i98$hbk$1@news.nyu.edu> Organization: Michigan Technological University Reply-To: adisaacs@mtu.edu Newsgroups: comp.unix.osf.osf1,comp.sys.dec NNTP-Posting-User: adisaacs@supreme.csl.mtu.edu The USENET cabal made Mark Bartelt say: >[ 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. exactly correct, in my opinion. The compiler can do anything it wants, as long as the result "looks like" the correct result from the program's perspective. (Of course, this could make debugging hard, but that's a "quality of implementation" issue.) If the code the compiler generates ends up generating the correct results, why should I care how it gets there? (By correct results, I include _everything_ observable about the program.) >[ 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. It's only a bug if your program can be affected by it. If you don't use the value of x anywhere, what does it matter what value x has? (Leaving the issue of debugging aside for the moment.) >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. Absolutely. However, the "bug" was observed by inspecting disassembled object code. This is a case of the "looks like" effect. If the code to the right of the || or && has no side effects, then the program _cannot know_ if the code was executed or not. In that case, the compiler is completely justified in executing the code anyway, if it wants to. If the code has some side effects, however, the compiler must ensure that it is not executed in error. End result? I am not convinced that this is a bug. If the compiler generates correct results for all cases, then it is not a bug. just my .02 pence, -andy -- Andy Isaacson -- conserve bandwidth, use one line sigs.