When do you use "if ( a = b )"? (was Re: Funn
Dave Schaumann
dave at cs.arizona.edu
Mon Mar 18 03:45:59 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?
How about:
if( ptr = malloc(sizeof(spam)) ) {
<stuff>
}
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 at cs.arizona.edu | Short .sig's rule!
More information about the Comp.lang.c
mailing list