When do you use "if ( a = b )"? (was Re: Funny mistake)

Jody Hagins hagins at gamecock.rtp.dg.com
Wed Mar 20 06:21:18 AEST 1991


In article <65837 at eerie.acsu.Buffalo.EDU>, chu at acsu.buffalo.edu (john c chu) writes:
|> In article <775 at camco.Celestial.COM> bill at 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 at autarch.acsu.buffalo.edu
|> 

-- 

Jody Hagins             
hagins at 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.



More information about the Comp.lang.c mailing list