Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!orion.cf.uci.edu!uci-ics!zardoz!tgate!ka3ovk!drilex!axiom!adelie!mirror!frog!john From: john@frog.UUCP (John Woods) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr), where cptr is a * Keywords: * != int Message-ID: <1650@frog.UUCP> Date: 19 Jul 89 21:17:00 GMT References: <10099@mpx2.mpx.com> <93@microsoft.UUCP> Organization: Misanthropes-R-Us Lines: 22 In article <93@microsoft.UUCP>, paulc@microsoft.UUCP (Paul Canniff 2/1011) writes: > >Would (!sptr) break anywhere? Should it be discouraged? > It will break if NULL != 0. It will break if-and-only-if your C compiler is broken. Read a C book, preferably the ANSI C spec. As far as discouragement goes, some feel that treating a pointer like a boolean is a mixing of abstractions that should be discouraged. Others (like myself) feel that treating it as success/failure makes the boolean interpretation quite natural. > > if (sptr= (struct xyzzy *)malloc(...), !sptr) > > fatal("cannot malloc"); > > This was from a *style* guide? Ew, ick, indeed! -- John Woods, Charles River Data Systems, Framingham MA, (508) 626-1101 ...!decvax!frog!john, john@frog.UUCP, ...!mit-eddie!jfw, jfw@eddie.mit.edu People...How you gonna FIGURE 'em? Don't bother, S.L.--Just stand back and enjoy the EVOLUTIONARY PROCESS...