This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] C undefined behavior fix


Paul Mackerras <paulus@samba.org> writes:

> I looked at this, and it starts out with an example that includes a
> statement free(p); (where p was assigned a value returned from malloc)
> and then states that "After the call to free the value of p is
> indeterminate."!
> 
> This seems absolutely and completely bogus to me.  Certainly, after
> the free, the value of *p is indeterminate, but the value of p itself
> *is* determinate; its value after the free is identical to its value
> before the free.  Why do they say that the value of p itself is
> indeterminate after the free?

One reason is that on some segmented machines, just loading the value
of 'p' into a segment register may cause an exception once its segment
has gone away.  

Another reason is to support garbage collection; you might want
'free(p)' to explicitly clear p and any other references to it that
can be found in the hope that will let the space be collected.

-- 
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]