Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!chalmers.se!mathrt0.math.chalmers.se!d9erikb From: d9erikb@dtek.chalmers.se (Erik Bergersjo) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funny mistake) Message-ID: <1991Mar21.213027.24314@mathrt0.math.chalmers.se> Date: 21 Mar 91 21:30:27 GMT References: <15481@smoke.brl.mil> <775@camco.Celestial.COM> <65837@eerie.acsu.Buffalo.EDU> Sender: d9erikb@dtek.chalmers.se Organization: Chalmers University of Technology, Gothenburg, Sweden. Lines: 24 In article <65837@eerie.acsu.Buffalo.EDU> chu@acsu.buffalo.edu (john c chu) writes: >[concerning "if ( a = b )" > >Is there a good use for this? There sure is. I can think of two major uses: (I) b is a function, perhaps returning a pointer to something on success and NULL otherwise. (II) b is a hardware register, cleared on reading. Of course, in both cases "a = b; if( a )..." would do, but if you don't have a good optimizing compiler the final code might get worse. Besides, I think "if(a = b)" is more readable. It's clearly one of those extra features / pecularities that make C the special language it is! =============================================================================== Chalmers University | . . | "A message worth of Technology | Real life: Erik Bergersj o | spreading is Sweden | E-mail: d9erikb@dtek.chalmers.se | worth reading" ===============================================================================