Who said P was pointing to a "copy of an array object"?
Pointer arithmetic is defined (in C 2018 6.5.6 8 and 9) in terms of pointers to array elements. For this purpose, a single object is treated as an array of one element. So, whenever we have any non-null object pointer, it is, in this model, pointing into an array.
Why did P "formerly" point to anything? That is, who says we've changed its value?
The text you quoted is saying “To figure out if E
is based on P
, let’s hypothetically make a copy of the array that P
is pointing into and then assign to P
a pointer into the corresponding place in the copy.” So the text you quoted is saying we are changing the value of P
, and then we are comparing the value of E
with this change and without it.
Let's suppose E is a pointer of local scope. Why would modifying any pointer expression other than the E pointer itself "change the value of E"? It could change the value pointed to by E maybe. Right?
Objects and values do not have scope. Identifiers have scope. But let’s consider an identifier with block scope:
// P is a pointer into A.
// S is the size of A.
// A is the start of an array not contained in any other array.
void foo(char *P, size_t S, char *A)
{
void *E = P+2;
}
For illustration, assume P
has value 0x1004 and A
is 0x1000. Is E
based on P
? Well, given the above, E
is 0x1006. Suppose we consider this code before the definition of E
:
char *N = malloc(S);
memcpy(N, A, S);
P = P - A + N;
Suppose malloc
returns 0x2000. What will the value of E
be? It will be 0x2006. That is different from 0x1006. Therefore E
is based on P
.
On the other hand, consider this:
void foo(char **P, size_t S, char **A)
{
#if OnOrOff
char *N = malloc(S);
memcpy(N, A, S);
P = P - A + N;
#endif
char **E = P[3];
}
Now, will the value of E
change depending on whether OnOrOff
is true or false? No, in either case it will receive the value that is the referenced element of A
, either directly or from the copy. The fact that P
might point into A
or N
does not affect the value of E
. So this E
is not based on P
.