When do you use "if ( a = b )"? (was Re: Funny mistake)

der Mouse mouse at thunder.mcrcim.mcgill.edu
Sat Mar 23 20:38:23 AEST 1991


In article <18401 at lanl.gov>, jlg at cochiti.lanl.gov (Jim Giles) writes:
> In article <11109 at dog.ee.lbl.gov>, torek at elf.ee.lbl.gov (Chris Torek) writes:
>> [I]f your compiler generates different code for
>> 	if (a = b)
>> than for
>> 	a = b; if (a)
>> then your compiler is not worth what you paid for it.  [...]

(I will assume you meant to say "better" instead of simply "different".
On a SPARC, for example, there are at least three ways of implementing
a test-for-zero, none of which is significantly better or worse than
any other....)

> Even if it was _free_!  The above 'optimization' was present in
> Fortran compilers more than 30 years ago - and [...].

Comparing FORTRAN optimizers to C optimizers is generally comparing
apples and oranges.  FORTRAN contains restrictions on the programmer
that allow the optimizer vastly more latitude.

Not that it's really got much to do with this case.  If `a' has no
side-effects (being a volatile variable counts as having side-effects),
you both are quite right: there is no excuse for it.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list