Path: utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!rtech!wong From: wong@rtech.UUCP (J. Wong) Newsgroups: comp.lang.c Subject: Helpful C Hint Keywords: ?: usage optimization Message-ID: <1971@rtech.UUCP> Date: 17 Apr 88 07:39:52 GMT Organization: Relational Technology Inc. Alameda, CA 94501 Lines: 18 Here's an interesting optimization (of which I'm sure some are already well aware :-) Occassionally, I write a conditional as follows: if ( ( a && b ) || ( !a && c && d ) ) error(); where "a" is often something like "version == 1". I dislike doing this because the condition "a" gets evaluated twice. I just realized I could rewrite this using the "?:" operator to only evaluate "a" once: if ( a ? ( b ) : ( c && d ) ) error(); (Depending on your compiler, this may not be more optimal.)