Re: ...malloc ...from Rome :-)
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 10/18/04
- Next message: Kenny McCormack: "Re: Access Violation in linked list"
- Previous message: Ben Pfaff: "Re: c equivalence of const_cast?"
- In reply to: James Stevenson: "Re: ...malloc ...from Rome :-)"
- Next in thread: James Stevenson: "Re: ...malloc ...from Rome :-)"
- Reply: James Stevenson: "Re: ...malloc ...from Rome :-)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 18 Oct 2004 18:40:31 GMT
"James Stevenson" <james@stev.org> wrote in message
news:Pine.LNX.4.44.0410181504470.6614-100000@beast.stev.org...
> > > free(pInt);
> > > }
> > >
> > > printf("Release memory previously allocated [%p]\n",pInt);
> >
> > This provokes undefined behavior -- you may not reference the value of
> > pInt in any way after it has been passed to free().
>
> Actually its not.
>
> if you define int *p;
> it is perforectly ok to access p but not ok to access *p
> after the free is performed.
I used to believe that too -- until I came to clc and
the kind folks here straightened me out. :-)
> Also what you seem to impliy is that the value of p
> will change once passed to the function free. This is also
> not true.
No, in itself that's not necessarily true. What *is* true
is that the standard specifically states that the result
of evaluating its value is undefined behavior.
>Only the memory address that p points to may / may not be
> changed. The actually value of p will remain constant.
It might, it might not. But that doesn't matter.
-Mike
- Next message: Kenny McCormack: "Re: Access Violation in linked list"
- Previous message: Ben Pfaff: "Re: c equivalence of const_cast?"
- In reply to: James Stevenson: "Re: ...malloc ...from Rome :-)"
- Next in thread: James Stevenson: "Re: ...malloc ...from Rome :-)"
- Reply: James Stevenson: "Re: ...malloc ...from Rome :-)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|