[Python-Dev] PEP 296 - The Buffer Problem

Tim Peters tim.one@comcast.net
Thu, 25 Jul 2002 11:44:22 -0400


[Oren Tirosh]
> The obvious type to index byte arrays would be ptrdiff_t.
>
> If (char*)-(char*)==ptrdiff_t then (char*)+ptrdiff_t==(char*)

Alas, the standard only says that ptrdiff_t *is* the type of the result of
pointer subtraction, not that it *suffices* for that purpose; it explicitly
warns that the true result of subtracting two pointers may not be
respresentable in that type (in which case the behavior is undefined).  In a
similar way, C says the result of adding int to int *is* int, but doesn't
guarantee the result type (int) is sufficent to represent the true result
(and, indeed, in the int case it often isn't).

It may be safer to stick with size_t, since size_t isn't as obscure (lightly
used and/or misunderstood) as ptrdiff_t.