Of course, highlighting and releasing the same pointer is well defined ...
void *p1 = malloc(42);
assert(p1);
...
free(p1);
... and conversion, although it intptr_t/uintptr_tcreates a comparable pointer (as in the case of "compare equal" C11 7.20.1.4) when these integer types exist, although not necessarily the same bit patterns. We can say that p2they p3have the same meaning, but can have different ideas.
void *p2 = malloc(42);
assert(p2);
uintptr_t u2 = (uintptr_t) p2;
...
void *p3 = (void *) u2;
if (p2 == p3) ...
if (memcmp(&p2, &p3, sizeof p2) == 0) ...
Now up free()through the comparable pointer.
The function freecalls up the space that it points ptrto ... if the argument does not match the pointer previously returned by the memory management function ... the behavior is undefined. C11dr §7.22.3.3 3
void *p4 = malloc(42);
assert(p4);
uintptr_t u4 = (uintptr_t) p4;
...
void *p5 = (void *) u4;
...
free(p5);
, , , :
"" "" free()?
, free(p5) undefined (UB), . - C, .