Undefined behavior or not?
Andrew Makhorin
mao@gnu.org
Sun Mar 12 01:12:00 GMT 2017
> No, that is not how it works. 6.2.4/2 says: [...] "The value of a
> pointer becomes indeterminate when the object it points to (or just
> past) reaches the end of its lifetime."
>
> It does not matter whether the value of p changes in *your* system,
> or in most systems. Using the value of p after deallocating the object
> it pointed to is undefined behaviour.
>
Does this mean that the following fragment is invalid? (I think it
isn't.)
void *p, *q;
p = malloc(123);
q = p;
free(p);
if (p == q) ...
Thanks.
Andrew Makhorin
More information about the Gcc-help
mailing list