"Clive D.W. Feather" <[EMAIL PROTECTED]> writes: > ptrdiff_t has to be able to hold the largest difference between two > pointers; it is a signed type.
The C standard does not require this. It allows an implementation, for example, where size_t is 64 bits, ptrdiff_t is 32, and objects can be created with more than 2**32 bytes. The behavior is undefined if you subtract two pointers into a same object and the resulting value does not fit into ptrdiff_t. See section 6.5.6 of the standard. My vague recollection is that ssize_t and SSIZE_MAX were put in precisely to support screwy implementations like Tandem. But this was a while ago and I wasn't there, so I could well be wrong. Also, ptrdiff_t and ssize_t were invented by different committees. Quite possibly they didn't want to step on each others' toes or assume each others' work. Early POSIX did not assume C89, so it couldn't assume ptrdiff_t. This most likely explains why there are two types. It'd be nice if someone wrote up the definitive story on this and put it into the POSIX rationale....