Checksum: 53543 Lines: 29 Path: utzoo!sq!msb From: msb@sq.uucp (Mark Brader) Date: Wed, 25-May-88 20:17:23 EDT Message-ID: <1988May25.201723.28041@sq.uucp> Newsgroups: comp.lang.c Subject: null pointers (was: negative addresses) Summary: ANSI does guarantee null pointer equality References: <2393@uvacs.CS.VIRGINIA.EDU> <21541@amdcad.AMD.COM> <10001@tekecs.TEK.COM> <206@proxftl.UUCP> Reply-To: msb@sq.UUCP (Mark Brader) Organization: SoftQuad Inc., Toronto > An interesting point: ANSI does not define (at least not anywhere > I can find it) the result of `x == y' when x and y are both null > pointers. No, this bug (which I, at least, pointed out in the first-round public comments) has been fixed in the January 1988 draft. I may as well quote the paragraph preceding the new one, as well. From section 3.2.2.3 (on page 38): # An integral constant expression with the value 0, or such an expression # converted to type void *, is called a "null pointer constant". If a null # pointer constant is assigned to or compared for equality to a pointer, # the constant is converted to a pointer of that type. Such a pointer, # called a "null pointer", is guaranteed to compare unequal to a pointer # to any object or function. # # Two null pointers, converted through possibly different sequences of # casts to pointer types, shall compare equal. By the way, section 4.1.5 guarantees on page 99 that the macro NULL, defined in certain standard #include headers, # expands to an implementation-defined null pointer constant thus it could be #defined as 0, 0L, (void*)0, 1-1, etc., but not (char*)0, which always was wrong. This has stayed the same through several drafts and I think it is most unlikely to change before the final Standard. Mark Brader, SoftQuad Inc., Toronto, utzoo!sq!msb, msb@sq.com #define MSB(type) (~(((unsigned type)-1)>>1))