2 ms·
According to the latest C standard draft that I could find, the semantics of realloc are that it deallocates the old object and allocates a new one. Of course,
by gpderetta 11y ago
According to the latest C standard draft that I could find, the semantics of realloc are that it deallocates the old object and allocates a new one. Of course, as an intended optimization, the new pointer value might have the same value as the old one, but that's not part of the semantics.
The only case in which the old pointer is not invalidated is if realloc fails.
As far as I know, in practice, at least with GCC, but likely clang as well, the compiler doesn't tracks the invalidation, but it simply assumes that any non null pointer returned by realloc (or any allocation function in fact) does not alias any other existing pointer in the program.