More damage to intuition (was RE: [Python-Dev] Comparison of recursive objects)

Thomas Wouters
Mon, 22 Jan 2001 14:52:44 +0100

On Sun, Jan 21, 2001 at 05:28:45PM -0500, Tim Peters wrote:
> [Thomas Wouters]
> > Why is comparing v->ob_type with w->ob_type illegal ? They're
> > both pointers to the same type, aren't they ?

> Non-equality comparison of pointers is defined if and only if the pointers
> are both addresses in the same contiguous structure (think struct or array);
> an exception is made for a pointer "one beyond the end" of an array, i.e. if

>     sometype a[N];

> then &a[0] < &a[N] == 1 is guaranteed despite that &a[N] is outside the
> bounds of a; but &a[0] < &a[N+1] is undefined (which *means* undefined!
> e.g., it's OK if they compare equal, or if the comparison causes a hardware
> fault, or ...).

Ok, I guess I stand corrected. I was confused by the name of Py_uintptr_t: I
thought it was a pointer-to-int, not an int large enough to hold a pointer.
I'm also positively appalled by the fact the standard refuses to define sane
behaviour for out-of-bounds access on an array, but attaches some weird
significance to what pointers are pointing *to*, when comparing the values
of those pointers, regardless of what type of object they are stored in. But
I guess I don't have to whine about that to you, Tim :-)

Thomas Wouters <>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!