Is the following well defined, for different values of REF
?
#include <stdio.h>
#define REF 1
#define S 1
int main(void) {
int a[2][S] = {{1},{2}};
int *q = REF ? a[1] : 0;
int *p = a[0] + S;
memcpy (&q, &p, sizeof q);
printf ("q[0] = %d\n", q[0]);
return 0;
}
Note that p
points to the after the last element of a[0]
, not to an element in the array a[0]
, hence not dereferenceable. But the address stored in p
is the address of a[1][0]
. p
semantically (intentionally?) points "to" (well, out of) a[0]
but physically points into a[1]
.
Can a copy of the bit pattern of a pointer point semantically to an object when the original only physically does?
SEE ALSO
I have asked essentially the same C/C++ question with a different "angle":