Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!lll-crg!lll-lcc!pyramid!decwrl!sun!guy From: guy@sun.UUCP Newsgroups: net.lang.c Subject: Re: Re: Re: Precedent for use of = Message-ID: <4971@sun.uucp> Date: Thu, 10-Jul-86 14:26:21 EDT Article-I.D.: sun.4971 Posted: Thu Jul 10 14:26:21 1986 Date-Received: Fri, 11-Jul-86 22:46:38 EDT References: <6056@sri-spam.ARPA> <502@cbmvax.cbmvax.cbm.UUCP> Organization: Sun Microsystems, Inc. Lines: 29 > > if (prog_name = rindex(*argv, '/')) > > prog_name++; > > else prog_name = *argv; ... > > > > prog_name = rindex(*argv, '/'); > > if (!prog_name) > > prog_name = *argv; > > else prog_name++; > The example that you show is good C, I use that style all of the time, > and a good compiler will produce code for it that's more efficient than > in the second example. Assuming your machine stores an indication of whether a "move" instruction moved a zero-or-non-zero value somewhere (which may or may not be the case; the MIPS chip, for example, has no condition code register), and assuming that your C implemention represents null pointers as all-zero bit patterns, a good compiler will realize that in the second example an indication of whether "prog_name" was assigned a zero value will be found there and will use it, in exactly the same fashion as it did in the first example, and will generate equally efficient code for both examples. If the aforementioned assumptions are not true, the conclusion that a good compiler will generate equally efficient code for both examples will almost certainly still be true. -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com (or guy@sun.arpa)