I'm wondering when I should use ptrdiff_t and size_t instead of int and
unsigned int or long and unsigned long? Is there any guideline I should
follow?
Peng
Yes, just use them for what they are intended for.
ptrdiff_t is a signed integer type which holds the difference between
two pointers. So use it when you want to represent the difference
between two pointers, when it is legal to do so.
size_t is an unsigned integer type which represents the size of an
object in bytes. It is the type produced by the sizeof operator and
is used as a parameter or return value of some library functions.
I imagine that there are 64 bit implementations right now where
ptrdiff_t and size_t are 64 bits, but signed and unsigned long are
only 32 bits. C++ does not yet have an integer type required to have
at least 64 bits.