more questions about efficient C code

Laurence Schmitt larry at cca.UUCP
Fri Jul 19 22:17:30 AEST 1985



>> 3) Is there really much to be gained by using assignment within
>>    a boolean expression, for example, is
>>
>>	if ((fp = fopen("foo", "r") == NULL) {
>>
>>    really that much faster than
>>
>>	fp = fopen("foo", "r");
>>	if (fp == NULL) {
>
>Again, depends: if "fp" is not a register, the assignment+test is faster,
>since you end up branching after the assignment from r0 to "fp".  If it
>is a register, it comes out the same.  (At least after optimization, usually).
>The first form is never slower, anyway.

In Lattice C on the IBM-PC the two constructs compile exactly the same--no
register declarations involved.



More information about the Comp.lang.c mailing list