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

Chris Torek torek at elf.ee.lbl.gov
Thu Mar 21 07:45:46 AEST 1991


In article <AV.91Mar20084724 at kielo.uta.fi> av at uta.fi (Arto Viitanen) writes:
[gcc version 1.39 on Sun-3, compiling `if (a = b)' vs `a = b; if (a)']
>In GNU cc, it was other way round: without optimization, assembler code
>was same, but with optimization, they were different.

That is peculiar.  I tried the same thing, with the same gcc, on the
same machine, and got identical code when optimized, different (poorer)
code for the second when not, exactly as expected.  (gcc without -O
typically produces truly awful code: the compiler relies quite heavily
on optimization to clean up after the initial code generation.  This
is reasonable, but does mean that you probably never should compile
without -O unless you are trying to debug the compiler itself.)
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek at ee.lbl.gov



More information about the Comp.lang.c mailing list