if vs ?: - (nf)

Guy Harris guy at rlgvax.UUCP
Sat Feb 18 17:05:07 AEST 1984


> 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



More information about the Comp.lang.c mailing list