Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!news.cs.indiana.edu!arizona.edu!arizona!dave From: dave@cs.arizona.edu (Dave Schaumann) Newsgroups: comp.lang.c Subject: Re: When do you use "if ( a = b )"? (was Re: Funn Message-ID: <1196@caslon.cs.arizona.edu> Date: 17 Mar 91 17:45:59 GMT References: <8148@rsiatl.Dixie.Com> <15481@smoke.brl.mil> <775@camco.Celestial.COM> <65837@eerie.acsu.Buffalo.EDU> Organization: U of Arizona CS Dept, Tucson Lines: 27 In article <65837@eerie.acsu.Buffalo.EDU> chu@acsu.buffalo.edu (john c chu) writes: |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? How about: if( ptr = malloc(sizeof(spam)) ) { } else panic( "Time to buy some more memory!" ) ; Now I realize that this is not the normal idiom for checking for a NULL malloc, but it does work, and has a certain charm in that the if-expression is rather simpler than the usual if( (ptr = malloc(sizeof(spam))) == NULL ) ...etc... -- Dave Schaumann | dave@cs.arizona.edu | Short .sig's rule!