Path: utzoo!attcan!uunet!peregrine!elroy!ames!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: pointers, tests, casts Message-ID: <14694@mimsy.UUCP> Date: 22 Nov 88 22:53:02 GMT References: <11130@dartvax.Dartmouth.EDU> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 31 In article <11130@dartvax.Dartmouth.EDU> ericb@libdev (Eric Bivona) writes: >I know about casting NULL or 0 to get an appropriate nil pointer ... Note that a cast is always sufficient, if not always necessary. (I find that much `extra' casting hampers readability, though.) [edited] > if (ptr == (char *)0) { /* or (char *)NULL */ >In assignments, a 0 or NULL is cast implicitly to the correct pointer >type .... Right. >What about the '==' comparison above? Would "(ptr == 0)" get evaluated >correctly? It would; the implicit cast occurs here, too. >... what about ... "(!ptr)"? That too is correct, by the rule that `!x' means `x == 0'. Stylistically, though, I prefer `if (ptr == NULL)'. In fact, the only place that `0' does not implicitly turn into the right kind of `nil' is in function calls (and, under dpANS rules, only those where prototypes are not present or insufficient to convey the necessary type information). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris