Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site alice.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: net.lang.c Subject: Re: condition convention 'if (10 == j)...' Message-ID: <3673@alice.UUCP> Date: Tue, 30-Apr-85 10:10:55 EDT Article-I.D.: alice.3673 Posted: Tue Apr 30 10:10:55 1985 Date-Received: Wed, 1-May-85 03:28:27 EDT References: <332@cubsvax.UUCP> Organization: Bell Labs, Murray Hill Lines: 13 > Just that instead of writing, in the traditional manner, > if(pc=malloc(nbytes)==NULL)... > you have to insert extra parens if you use the other form: > if(NULL==(pc=malloc(nbytes))).. > This is because == has higher precedence than =, and the expression will > first evaluate NULL==pc, then try to set the resulting constant to whatever > malloc() returns (except, of course, the compiler doesn't let you get that far). If you write if(pc=malloc(nbytes)==NULL)... that will set pc to 1 if malloc succeeds and 0 if it fails. You need the parens anyway: if((pc=malloc(nbytes)==NULL)...