Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!apple!netcom!amdcad!dgcad!dg-rtp!gamecock!hagins From: hagins@gamecock.rtp.dg.com (Jody Hagins) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funny mistake) Message-ID: <1991Mar22.162117.25000@dg-rtp.dg.com> Date: 22 Mar 91 16:21:17 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> <11309@dog.ee.lbl.gov> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Reply-To: hagins@gamecock.rtp.dg.com (Jody Hagins) Organization: Data General Corporation, Research Triangle Park, NC Lines: 66 In article <11309@dog.ee.lbl.gov>, torek@elf.ee.lbl.gov (Chris Torek) writes: |> [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) ... That's exactly what Borland's C compilers do. |> |> 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 |> -- Jody Hagins hagins@gamecock.rtp.dg.com Data General Corp. 62 Alexander Dr. RTP, N.C. 27709 (919) 248-6035 Nothing I ever say reflects the opinions of DGC.