Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!viusys!uxui!unislc!ttobler From: ttobler@unislc.uucp (Trent Tobler) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funny mistake) Message-ID: <1991Mar20.191103.10242@unislc.uucp> Date: 20 Mar 91 19:11:03 GMT Article-I.D.: unislc.1991Mar20.191103.10242 References: <65837@eerie.acsu.Buffalo.EDU> Organization: unisys Lines: 28 From article <65837@eerie.acsu.Buffalo.EDU>, by chu@acsu.buffalo.edu (john c chu): > 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? Yes. I often use it to do the following... --------------------- if( fp = fopen( fname, "r")) { do_stuff_to(fp); fclose(fp); } else perror( fname); ---------------------- Of course, it could be written with fp = fopen ... on a line by itself, followed by an if(fp) ... , but I find the above easier to follow. -- Trent Tobler - ttobler@csulx.weber.edu , ttobler@unislc!sun!uucp