Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: What C compilers have non-zero null pointers? Message-ID: <1990Jul10.155941.11656@zoo.toronto.edu> Organization: U of Toronto Zoology References: <422@minya.UUCP> Date: Tue, 10 Jul 90 15:59:41 GMT In article <422@minya.UUCP> jc@minya.UUCP (John Chambers) writes: >Consider that the C bible (page 192) says, concerning assignments >to/from pointers and other types, "The assignment is a pure copy >operation, with no conversion." This means that in: > int i; > char*p; > i = 0; > p = i; >the value assigned to p is the same bit pattern as i... Reading the Old Testament (K&R1) and trying to apply it to modern C is a mistake. This code isn't even legal nowadays. You need an explicit cast to turn the int into a pointer, and there is no promise that that cast doesn't do some sort of arcane conversion operation. Actually, even the Old Testament continued with: "This usage is nonportable, and may produce pointers which cause addressing exceptions when used. However, it is guaranteed that assignment of the *constant* 0 to a pointer will produce a null pointer distinguishable from a pointer to any object." [emphasis added] The constant 0 in a pointer context has no relationship whatsoever to the integer value 0; it is a funny way of asking for the null pointer, which need not resemble the int value 0 in any way. -- NFS is a wonderful advance: a Unix | Henry Spencer at U of Toronto Zoology filesystem with MSDOS semantics. :-( | henry@zoo.toronto.edu utzoo!henry