Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!sun-barr!cs.utexas.edu!csd4.milw.wisc.edu!lakesys!chad From: chad@lakesys.UUCP (D. Chadwick Gibbons) Newsgroups: comp.lang.c Subject: null pointers Keywords: null Message-ID: <883@lakesys.UUCP> Date: 24 Jul 89 10:08:29 GMT Reply-To: chad@lakesys.lakesys.COM (D. Chadwick Gibbons) Distribution: usa Organization: Lake Systems - Milwaukee, Wisconsin Lines: 42 I have seen so many contradictions of the defintion of null and most of the constant discussion of it has caused my sensability of the defintion of null to fly way out in left field. Let me equate to you my current understanding of the null pointer, and if anyone wishes, they may mail me a different story. I don't think the news group needs another rash of postings, so let's stay away from that. As defined by K&R2 (A6.6, p. 198) null is "An integral constant expression with [the] value 0, or such an expression cast to type void * [which may be] converted, by a cast, by assignment, or by comparision, to a pointer of any type." Which means to me that if you state a comparision such as "if (ptr == 0)" then you are indeed checking for a null pointer in a valid way. On the actual symbolic constant of NULL, The Book says (p. 102): "The symbolic constant NULL is often used in place of zero, as mnemonic to indicate more clearly that this is a special value for a pointer." Fine. That makes sense. From what I have seen however, NULL may not be a number with a zero bit pattern, since some implementations do not store zero as a zero bit pattern (depending if the value in question is signed or unsigned.) Thus, zero and NULL may not equal each other in all implementations, yet _both_ may be used to safely in comparision of a null pointer. It appears that in pre-ANSI C, this is not true, and often the symbol constant NULL requires casting to the proper type to ensure proper conversion of alignment restrictions. And then there is the problem of some architectures storing data at address zero. Occording to the defintions above - this does not matter. It is the compilers job to assume that the constant zero is for checking for a null pointer, and if valid data can be at address zero that comparing a pointer against zero is _not_ a comparision with that address. Or so I have extrapolated. If you respond to this in way, shape, or form, try reading the whole thing first, go grab something with caffiene in it, and then respond. -- D. Chadwick Gibbons, chad@lakesys.lakesys.com, ...!uunet!marque!lakesys!chad