TITLE: null and pointer representations (Newsgroups: comp.std.c++, 7 Dec 98) KELLNER: "Alfred Kellner" >> T*t=0; Has been meant as an address designating the very first >> element of the lagest array of the smallest type that can exist in a given >> address space - not as claim *that* address *is* the NULL pointer, in >> fact, it cannot be (..is distinguishible from every other value of >> pointer..). CLAMAGE: Steve Clamage > In fact it MUST be a null pointer. A language requirement is that > a literal zero assigned to a pointer type yields a null pointer > of that type, distinguishable from a pointer to any object (or > function) of that type. > > For example, a simple implementation on a system with a linear > address space is for address zero to be reserved, and not used > as the address of any entity in the program. > > An implemenation can choose to use something else for a null > pointer. In that case, assigning a literal zero to a pointer > object does not result in all-bits-zero, but in some other > value that is never used for any entity in the program. KELLNER: >> However, the question is still : Is an address a number ? ???: >>> Furthermore, your use of the term ordinal implies that arbitrary pairs >>> of addresses can be ordered. KELLNER: >> Agreed, that's implied in pointer arithmetic ++ptr gets the next ptr in >> sequence, and ptr+n the (1+n)-th. CLAMAGE: > No, that operation is only well-defined for objects within the > same array. The operation result is not defined once you go outside > the bounds of the array. (The address of array+n for an array of > n elements is defined.) > > Arbitrary pairs of of addresses need not have any such relationship. ???: >>> There are implementations where that doesn't work either. KELLNER: >>*This* comes as a very surprise to me. Pointer arithmetic doesn't work ? CLAMAGE: > It's only defined when the results remain within the same complete > object. Example: > char A[100]; > char *P = A + 101; // 2 past the end of A > The addition of A and 101 is not guaranteed to produce a result; > if it does, the assignment to P is not guaranteed to succeed; > if it does, no operation on P except a new assignment has any > defined result. That is, you are not guaranteed even to be able > to inspect the value of the pointer P.