Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA Path: utzoo!linus!bbncca!keesan From: keesan@bbncca.ARPA (Morris Keesan) Newsgroups: net.lang.c Subject: Re: if vs ?: - (nf) Message-ID: <585@bbncca.ARPA> Date: Thu, 16-Feb-84 11:36:27 EST Article-I.D.: bbncca.585 Posted: Thu Feb 16 11:36:27 1984 Date-Received: Fri, 17-Feb-84 06:15:57 EST References: <1593@pur-ee.UUCP> Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 30 ------------------------------ It is unclear that there will be any differences between the compiled code for if (i) j++; else k++; and i ? j++ : k++ ; Certainly, the compiler's discarding of statements with no side effects doesn't imply anything of the sort. I recently made a similar enhancement to BBN's C compiler (based on the Dennis Ritchie PDP-11 C compiler), making it not generate code for operations with no side effects (such as the statement "i+j;"), and when I ran the two statements above through it, it produced identical code. In my case, this means that I didn't include ?: in my list of "operators with no side effects". I see no reason to expect that the implementers of Lattice C were any less careful. An interesting effect of the way I implemented the enhancement is that I get different code for if (i) j+1 ; else k+1; and i ? j+1 : k+1 ; because in the first case j+1 and k+1 are statements, and thus get discarded, leaving an empty "if" framework which gets dropped by the optimizer. In the second case, j+1 and k+1 are subexpressions of ?:, and the additions get generated. I'm not too concerned about this, since the main reason for my enhancement was to avoid generating unnecessary conversion code for some casts being generated internally. It would be interesting to see what the Lattice C compiler does with this, though. -- Morris M. Keesan {decvax,linus,wjh12,ima}!bbncca!keesan keesan @ BBN-UNIX.ARPA