use of if (!cptr) and if (cptr), where cptr is a *
John Woods
john at frog.UUCP
Thu Jul 20 07:17:00 AEST 1989
In article <93 at microsoft.UUCP>, paulc at 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 at frog.UUCP, ...!mit-eddie!jfw, jfw at eddie.mit.edu
People...How you gonna FIGURE 'em?
Don't bother, S.L.--Just stand back and enjoy the EVOLUTIONARY PROCESS...
More information about the Comp.lang.c
mailing list