Precedent for use of =

guy at sun.UUCP guy at sun.UUCP
Fri Jul 11 04:26:21 AEST 1986


> >     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 at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list