Path: utzoo!utgpu!water!watmath!clyde!att!ucbvax!decwrl!sun!limes@ouroborous From: limes@ouroborous (Greg Limes) Newsgroups: comp.lang.c Subject: Re: C IF statement efficiency... Keywords: c if Message-ID: <65327@sun.uucp> Date: 23 Aug 88 17:41:34 GMT References: <8808171400.AA05122@ucbvax.Berkeley.EDU> <566@sybase.sybase.com> Sender: news@sun.uucp Reply-To: limes@ouroborous (Greg Limes) Distribution: na Organization: Sun Microsystems, Inc. Lines: 20 In-reply-to: ben@bosco.UUCP (ben ullrich) In article <8808171400.AA05122@ucbvax.Berkeley.EDU> U23405@UICVM writes: >I was wondering if, of the two following program fragments, which one would >be compiled more efficiently by most C compilers: > > if (big > small) if (big > small) > return big; return big; > else return small; > return small; In article <566@sybase.sybase.com>, ben@bosco (ben ullrich) writes: >how about > return ((big > small) ? big : small) >i don't know how efficient this is, but it is certainly more succinct than >those suggested in the quoted text above. All three of these examples reduce to the same thing quite early on in the compilation; in fact, the compiler on my workstation (SunOS 4.0) produces code for them that differs only in the names of some of the temporary labels used. --