Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!newstop!exodus!appserv!sun!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: <1991Mar19.202118.11505@dg-rtp.dg.com> Date: 19 Mar 91 20:21:18 GMT References: <8148@rsiatl.Dixie.Com> <15481@smoke.brl.mil> <775@camco.Celestial.COM> <65837@eerie.acsu.Buffalo.EDU> 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: 42 In article <65837@eerie.acsu.Buffalo.EDU>, chu@acsu.buffalo.edu (john c chu) writes: |> In article <775@camco.Celestial.COM> bill@camco.Celestial.COM (Bill Campbell) writes: |> [concerning "if ( a = b )" |> >Certainly it |> >is a legal construction, but 90% of the time when I do this it |> >was my mistake! |> |> It's been my mistake everytime I've done it!! I realize that it is a |> legal construction and I know what it does, but I was wondering... |> Is there a good use for this? Sure. Any time you want to test the result of an assignment. However, you might want to use this instead: if ((a = b) != 0) The compiler SHOULD generate the same code, but you do not get the headaches that can result from: if (a = b) |> |> john |> chu@autarch.acsu.buffalo.edu |> -- 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.