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

Tomas Ruden tomas at u30003.rsv.svskt.se
Fri Mar 22 21:11:11 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:
>|> [...]
>|> Smaller source code, yes.  Smaller or faster object code---well, if
>|> 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.  [...]
>
>Even if it was _free_!  The above 'optimization' was present
>in Fortran compilers more than 30 years ago - and their _fastest_
>machines were slow compared to today's micros (so the excuse that
>doing the above analysis makes the compiler too slow or complex is
>garbage).
>
>J. Giles

I agree!  A smart programmer can, when knowing the architecure of a CPU,
make code that is fast for that special CPU.  Those who are writing
the codegenerator for a compiler should have that knowledge and make
use of it.  When I am writing C-code, now on RISC-computer, can't write
code that is 'smart' for that perticular architecture because then
it's certanly not 'smart' for a VAX or a 386.

I use theese "if( a=b )" type of constructions because I that it's clearly
defined i C what it means and I don't think it's any obscurement. I
especially use it in "while( c=nextchar() )" kind of constructions. I
belive that when I have to think more carefully about what I have between
the ()'s I don't tend to do the mistake of using '=' instead of '=='
especially often.
-- 
Tomas Ruden,  ...!sunic!u30003!tomas or tomas at u30003.rsv.svskt.se
Don't blame the Swedish Tax      !  I wish I had an English
Administration for my opinions   !  spellingchecker



More information about the Comp.lang.c mailing list