Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site decvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!minow From: minow@decvax.UUCP (Martin Minow) Newsgroups: net.lang.c Subject: Re: more questions about efficient C code Message-ID: <90@decvax.UUCP> Date: Tue, 25-Jun-85 22:14:32 EDT Article-I.D.: decvax.90 Posted: Tue Jun 25 22:14:32 1985 Date-Received: Thu, 27-Jun-85 05:27:39 EDT References: <474@crystal.UUCP> <397@umcp-cs.UUCP> <721@wlcrjs.UUCP> Reply-To: minow@decvax.UUCP (Martin minow) Distribution: net Organization: DEC - ULTRIX Engineering Group Lines: 19 The question was asked whether the common C idiom if ((fp = fopen("foo.bar", "r")) == NULL) { ... really is more efficient than fp = fopen("foo.bar", "r"); if (fp == NULL) { ... In response, Joe Durnavich makes the good point that the saving of one measly move instruction (which a good compiler would optimize out anyway) isn't worth the effort. In response, I would again point out that this is a C idiom -- one of the habits a programmer picks up for better or worse. In defense, I would note that writing this as a single statement ties (visually) the if condition closer to the fopen() result that is being tested than would be the case were one to write two statements. Martin Minow decvax!minow