J
James Harris
This post is really about how size_t, ssize_t and ptrdiff_t are intended to
be used but first, have I got the following right about the basics?
* size_t: able to hold the size of the largest object, always unsigned,
returned by sizeof.
* ssize_t: possibly not a C standard type, perhaps part of Posix, able to
hold the size of most objects or -1 but usually able to also hold a wider
range of negative numbers than just -1
* ptrdiff_t: signed difference between two pointers to parts of the same
object
It's not so much their mechanics but the intents and limits puzzle me a bit
so....
Are all three needed? With a clean slate, would different definitions be
better? Does C have it right to just have the two and was Posix right to add
a signed version of size_t? Would any implementation of ssize_t ever be
different from that of ptrdiff_t?
It seems there is or was the potential for code pointers and data pointers
to be different sizes, e.g. as in the old segmentation models where one
could be 16 bits and the other could be larger. If so, should there be
pointer difference and size variants for code and data or should the old
models simply never have existed? (Rhetorical!) With x86-64 should C have
different sizes of code and data pointers? (I sure hope not.)
If an implementation allowed a single object to be bigger than half the
address space could operations on it break code using ssize_t and ptrdiff_t,
when the result is out of range of the signed type?
These are the only types I am aware of which are designed specifically to
represent quantities of bytes of memory. Does C have any others that I have
missed?
James
be used but first, have I got the following right about the basics?
* size_t: able to hold the size of the largest object, always unsigned,
returned by sizeof.
* ssize_t: possibly not a C standard type, perhaps part of Posix, able to
hold the size of most objects or -1 but usually able to also hold a wider
range of negative numbers than just -1
* ptrdiff_t: signed difference between two pointers to parts of the same
object
It's not so much their mechanics but the intents and limits puzzle me a bit
so....
Are all three needed? With a clean slate, would different definitions be
better? Does C have it right to just have the two and was Posix right to add
a signed version of size_t? Would any implementation of ssize_t ever be
different from that of ptrdiff_t?
It seems there is or was the potential for code pointers and data pointers
to be different sizes, e.g. as in the old segmentation models where one
could be 16 bits and the other could be larger. If so, should there be
pointer difference and size variants for code and data or should the old
models simply never have existed? (Rhetorical!) With x86-64 should C have
different sizes of code and data pointers? (I sure hope not.)
If an implementation allowed a single object to be bigger than half the
address space could operations on it break code using ssize_t and ptrdiff_t,
when the result is out of range of the signed type?
These are the only types I am aware of which are designed specifically to
represent quantities of bytes of memory. Does C have any others that I have
missed?
James