Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funny mistake) Message-ID: <11309@dog.ee.lbl.gov> Date: 22 Mar 91 07:25:12 GMT References: <8148@rsiatl.Dixie.Com> <15481@smoke.brl.mil> <775@camco.Celestial.COM> <65837@eerie.acsu.Buffalo.EDU> <1991Mar18.195351.11985@unlv.edu> <11109@dog.ee.lbl.gov> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 48 X-Local-Date: Thu, 21 Mar 91 23:25:12 PST [I wrote: `if your compiler generates different code for embedded assignments than for separate assignments, that compiler is not worth what you paid for it.'] In article Sepp@ppcger.ppc.sub.org (Josef Wolf) writes: >You might be right in this point of view, but... [and goes on to argue that embedded assignment tends to be clearer.] I happen to agree---most often, a loop like: while ((c = getchar()) != EOF) { do some work; } is MUCH better, stylistically, than c = getchar(); while (c != EOF) { do some work; c = getchar(); } (Never mind translating into `for' loop syntax :-) ) >Well, the above is _my_ opinion. You have to find _your_ way to get >around this problem. Do not make the mistake of thinking that every argument I make is a direct clue to my own opinions. I could, for instance, show how VMS is better than Unix at some particular task. (Such tasks do exist, especially with older Unixes.) Nonetheless, I have managed to avoid VMS systems for many years now, and plan to continue avoiding them. In this particular case, I would be quite happy with a compiler that warns about if (a = expr) ... but not about if ((a = expr) != 0) ... and I tend to write the latter when I mean `assign, then test the result'. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov