Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!ames!think!redsox!campbell From: campbell@redsox.bsw.com (Larry Campbell) Newsgroups: comp.lang.c Subject: Re: use of if (!cptr) and if (cptr), where cptr is a * Keywords: * != int Message-ID: <803@redsox.bsw.com> Date: 18 Jul 89 23:42:35 GMT References: <10099@mpx2.mpx.com> Reply-To: campbell@redsox.UUCP (Larry Campbell) Organization: The Boston Software Works, Inc. Lines: 22 We use macros called NIL and NEW: #define NIL(type) ((type) 0) #define NEW(type) ((type *) malloc(sizeof(type))) We also use typedefs to save typing and centralize type information, so the malloc example looks like this: typedef struct foo FOO; FOO *p; p = NEW(FOO); if (p == NIL(FOO *)) error(); I think this makes it pleasingly clear that you're testing for an invalid pointer, rather than the quantity zero. -- Larry Campbell The Boston Software Works, Inc. campbell@bsw.com 120 Fulton Street wjh12!redsox!campbell Boston, MA 02146