Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!enea!u30003!tomas From: tomas@u30003.rsv.svskt.se (Tomas Ruden) Newsgroups: comp.lang.c Subject: Optimization (was:Re: When do you use "if ( a = b )"?) Message-ID: <1991Mar22.111111.18345@u30003.rsv.svskt.se> Date: 22 Mar 91 11:11:11 GMT References: <1991Mar18.195351.11985@unlv.edu> <11109@dog.ee.lbl.gov> <18401@lanl.gov> Organization: Swedish Tax Administration Lines: 40 In article <18401@lanl.gov> jlg@cochiti.lanl.gov (Jim Giles) writes: >In article <11109@dog.ee.lbl.gov>, torek@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@u30003.rsv.svskt.se Don't blame the Swedish Tax ! I wish I had an English Administration for my opinions ! spellingchecker