What is the restriction on the distance between pointers of a certain type in C ++?

Suppose I have two pointers for input T:

T* first = ...// whatever
T* second = ... //whatever else

Can I be sure that the distance between these two pointers can never exceed:

((size_t)(-1))/sizeof(T)?

+5
source share
1 answer

You can only calculate the distance between two pointers (subtract one pointer from the other) if both pointers point to elements in the same array or to one end of the end of the same array.

, , ((size_t)(-1)) / sizeof(T), size_t , .

, .

+13

All Articles