The C standard (ISO/IEC 9899:2011 or 9899:1999) defines a type ptrdiff_t
in
.
The POSIX standard (ISO/IEC 9945; IEEE Std 10
The Open Group Base Specifications Issue 7, IEEE Std 1003.1, 2013 Edition, description of <sys/types.h> says:
The type ssize_t is capable of storing values at least in the range [-1, SSIZE_MAX].
In other words, ssize_t
is signed, but the set of negative values it can represent may be limited to just {-1}.
A ptrdiff_t
, on the other hand, is guaranteed to have a more symmetric positive/negative range.
I admit that in practice, it doesn't seem likely that ssize_t
would be this limited in the negative range, but it is possible.
Of course, another difference is that ptrdiff_t
is available whenever you're programming in standard C or C++, but ssize_t
may not be available unless you're targeting a standard POSIX system.
Is there an implementation where the underlying base type for ssize_t is not the same as for ptrdiff_t?
x86-16 with the large memory model. Pointers are far (32-bit), but individual objects are limited to one segment (so size_t
is allowed to be 16-bit).