Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/5/84; site wlcrjs.UUCP
Path: utzoo!watmath!clyde!cbosgd!ihnp4!wlcrjs!jjd
From: jjd@wlcrjs.UUCP (Joe Durnavich)
Newsgroups: net.lang.c
Subject: Re: more questions about efficient C code
Message-ID: <721@wlcrjs.UUCP>
Date: Tue, 25-Jun-85 01:30:55 EDT
Article-I.D.: wlcrjs.721
Posted: Tue Jun 25 01:30:55 1985
Date-Received: Wed, 26-Jun-85 05:40:13 EDT
References: <474@crystal.UUCP> <397@umcp-cs.UUCP>
Reply-To: jjd@wlcrjs.UUCP (Joe Durnavich)
Distribution: net
Organization: chi-net, Public Access UN*X, Chicago IL
Lines: 30


>> 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.

	This example bothers me.  I'm not sure what all makes up the
	fopen subroutine, but the addition or subtraction of one measely
	assignment statement *has* to be negligible when compared to what
	goes on in fopen.  Even if that code is in the innermost of inner
	loops, the "optimization" will still be unnoticable.  I know
	it's just an example of an assignment within a boolean expression,
	but I see a *lot* of programs with that same code.  Are we really
	gaining anything, or is it merely psychological?

					Joe Durnavich
					ihnp4!wlcrjs!jjd

No part of this message may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, without the permission of the author.