Re: free()
- From: "Beej" <beej@xxxxxxx>
- Date: 14 Feb 2007 02:35:20 -0800
On Feb 13, 1:38 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
Short of writing an entire pointer management subsystem, there isn't
much you can do with a pointer to check it for validity, but you *can*
test it against NULL. If you know it's NULL, you know it's invalid. If
it isn't NULL, you can't be sure either way. So setting it to NULL when
it would otherwise be indeterminate is a Good Thing, because it
increases the amount of information available to you at a trivial cost.
At last... this thread is finally starting to boil down to "NULL makes
a great sentinel value." ;)
-Beej
void delete_goat(GOAT *g)
{
free(g);
g = NULL;
}
.
- Follow-Ups:
- Re: free()
- From: Chris Dollin
- Re: free()
- References:
- free()
- From: dbansal
- Re: free()
- From: santosh
- Re: free()
- From: Racaille
- Re: free()
- From: santosh
- Re: free()
- From: Richard Bos
- Re: free()
- From: Ian Collins
- Re: free()
- From: Christopher Benson-Manica
- Re: free()
- From: Richard Heathfield
- free()
- Prev by Date: Re: free()
- Next by Date: Re: free()
- Previous by thread: Re: free()
- Next by thread: Re: free()
- Index(es):
Relevant Pages
|