On my system both ptrdiff_t
and size_t
are 64-bit.
I would like to clarify two things:
I believe that no array could be as large as size_t
due to address space restrictions. Is this true?
If yes, then, is there a guarantee that ptrdiff_t
will be able to hold the result of subtraction of any pointers within the max-sized array?
No, there is no such guarantee. See, for example, here: https://en.cppreference.com/w/cpp/types/ptrdiff_t
If an array is so large (greater than PTRDIFF_MAX elements, but less than SIZE_MAX bytes), that the difference between two pointers may not be representable as std::ptrdiff_t, the result of subtracting two such pointers is undefined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With