Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr), where cptr is a * Message-ID: <10544@smoke.BRL.MIL> Date: 17 Jul 89 15:34:44 GMT References: <10099@mpx2.mpx.com> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 12 In article <10099@mpx2.mpx.com> erik@mpx2.mpx.com (Erik Murrey) writes: >Would (!sptr) break anywhere? Should it be discouraged? When sptr is a pointer variable, the following are equivalent: if(!sptr) if(sptr==0) if(sptr==NULL) /* assuming NULL is properly defined */ There is no need to cast the 0 (or NULL) to the type of sptr for this comparison. A common idiom is if ( (sptr = (type *)malloc( size )) == NULL )