Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!nntp-server.caltech.edu!suncub.bbso.caltech.edu!EYCHANER From: eychaner@suncub.bbso.caltech.edu (Amateurgrammer) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funny mistake) Message-ID: <1991Mar17.185656.7457@nntp-server.caltech.edu> Date: 17 Mar 91 18:56:56 GMT References: <8148@rsiatl.Dixie.Com> <15481@smoke.brl.mil> <775@camco.Celestial.COM>,<65837@eerie.acsu.Buffalo.EDU> Sender: news@nntp-server.caltech.edu Reply-To: eychaner@suncub.bbso.caltech.edu Organization: Big Bear Solar Observatory, Caltech Lines: 21 chu@acsu.buffalo.edu (john c chu) writes: >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. That's an easy one. Example: if (stat = some_func(...)) printf("Error %d: %s\n", stat, errstr(stat)); some_func(...) is a function which returns 0 if it completes successfully, and an error code processed to s string by errstr(stat) if it fails. I know this isn't the greatest code, but you get the idea (I hope...). ****************************************************************************** Glenn Eychaner - Big Bear Solar Observatory - eychaner@suncub.bbso.caltech.edu "Studies have shown that it is cheaper to build things that don't work than things that do." -Jeff Nenow, BBSO