C IF statement efficiency...
Greg Limes
limes at ouroborous
Wed Aug 24 03:41:34 AEST 1988
In article <8808171400.AA05122 at ucbvax.Berkeley.EDU> U23405 at 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 at sybase.sybase.com>, ben at 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.
--
More information about the Comp.lang.c
mailing list