Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1a 12/4/83; site rlgvax.UUCP Path: utzoo!linus!decvax!harpo!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: if vs ?: - (nf) Message-ID: <1727@rlgvax.UUCP> Date: Sat, 18-Feb-84 02:05:07 EST Article-I.D.: rlgvax.1727 Posted: Sat Feb 18 02:05:07 1984 Date-Received: Sun, 19-Feb-84 02:49:09 EST References: <585@bbncca.ARPA> <476@abnjh.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 32 > The system V pcc compiler for the 3B20S generates two more > instructions for > "i ? j++ : k++ ;" > than it does for > "if (i) j++ else k++;" > In the former case, it is apparently attempting to get the > value of the result of the expression (namely the prior value > of j or k, depending on the value of i) into a register. > Even though it never uses the value in the register for anything! > It does this regardless of the setting of the "-O" (optimize) flag. > The only effect of the -O flag is to replace jumps to returns by > returns. Well, if you said l = i ? j++ : k++ ; it would be using the value in question (the previous value of j or k). Either it's too tricky to teach PCC how to deal with expressions whose value is being thrown out (I suspect, by the way, that explicitly throwing the value out by casting to "void" won't help), or it was decided that it wasn't worth the trouble. Also, "-O" isn't a full-blown optimizer, it's a peephole and "final" (to use Bliss-11 compiler terminology) optimizer and doesn't catch all suboptimal code. Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy