On Tue, Jul 12, 2005 at 03:08:54PM -0700, Joe Buck wrote: > On Tue, Jul 12, 2005 at 11:42:23PM +0200, Erik Trulsson wrote: > > Pointer subtraction is only well defined if both pointers point to elements > > in the same array (or one past the end of the array). Otherwise the > > behaviour is undefined. > > While this is correct, there are certain cases that the standard leaves > undefined but that nevertheless can be useful; for example, pointer > subtraction can be used to estimate the amount of stack in use (of > course, it is necessary to know if the stack grows upward or downward). > > Similarly, in an OS kernel, comparing pointers may make sense.
Yes, there are some situations where it can be useful to compare pointers to different objects, but then you need to make sure that the compiler you use actually supports that. I believe most C compilers support it in practice, but few, if any, have actually documented it as a supported extension to C. -- <Insert your favourite quote here.> Erik Trulsson [EMAIL PROTECTED]