Path: utzoo!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!apple!mauxci!problem!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? Message-ID: <1991Mar18.143348.3595@druid.uucp> Date: 18 Mar 91 14:33:48 GMT References: <15481@smoke.brl.mil> <775@camco.Celestial.COM> <65837@eerie.acsu.Buffalo.EDU> Organization: D'Arcy Cain Consulting, West Hill, Ontario Lines: 29 In article <65837@eerie.acsu.Buffalo.EDU> john c chu writes: >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? Certainly: if (a = b()) ...; Where the body uses the value returned from b(). For readability you could write: a = b(); if (a) ...; but that isn't very efficient. I prefer the following: if ((a = b()) != 0) ...; On any reasonable compiler that should generate the same code as the first example but my intention is perfectly clear. Anyone trying to maintain my code doesn't have to investigate the surrounding code when he sees that to figure out if I really meant it. -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | There's no government Toronto, Ontario, Canada | like no government! +1 416 424 2871 |