Let's consider this code:
char arr[10];
char *ptr1 = &arr[0];
char *ptr2 = &arr[5];
or
int i;
char *ptr1 = &i;
char *ptr2 = ptr1 + 1;
Clearly, these two pointers points to the same object. But is there any way to determine this afterwards in code? Is it possible to write a function like this?
// Returns true if p1 and p2 points to the same object and false otherwise
bool same_object(void *p1, void *p2) {
if(<condition>)
return true;
return false;
}
I suspect this is impossible since you cannot retrieve the size of an array just from a pointer, but I wanted to make sure if there's something I may have overlooked.