Re: assigning pointer to NULL
- From: dj3vande@xxxxxxxxxxxxxxxxxxxxxxxxxxx
- Date: Wed, 30 Jan 2008 17:25:15 +0000 (UTC)
In article <47a03c63.2858170722@xxxxxxxxxxxxxx>,
Richard Bos <rlb@xxxxxxxxxxxxxxxxxxxxxx> wrote:
"Roman Mashak" <mrv@xxxxxxxx> wrote:
is it legal to destroy the memory pointed to by a pointer and then assign
NULL to it? Say, like this:
char *ptr;
ptr = malloc(10);
free(ptr);
ptr = NULL;
Legal, but useless.
Not completely useless, only mostly.
If you know that the pointer you're setting to NULL was the only
pointer into that memory, then it's perfectly safe and useful.
(This is rare, but not unheard of.)
It's also not unreasonable to use the non-null-ness of a pointer as a
flag that you have useful information of some sort, and to want to
discard that information before you have something else to replace it
with.
(There are intelligent people who disagree with other intelligent
people about whether this indicates a design flaw.)
dave
--
Dave Vandervies dj3vande at eskimo dot com
I like "fun" risks, rather than "lazy" risks.
(If I'm going to kill myself, I want to have a good time on the way.)
--Graham Reed in the scary devil monastery
.
- Follow-Ups:
- Re: assigning pointer to NULL
- From: ymuntyan
- Re: assigning pointer to NULL
- References:
- assigning pointer to NULL
- From: Roman Mashak
- Re: assigning pointer to NULL
- From: Richard Bos
- assigning pointer to NULL
- Prev by Date: Re: How to call function whose function call with arguments is in a string Options
- Next by Date: Re: A solution for the allocation failures problem
- Previous by thread: Re: assigning pointer to NULL
- Next by thread: Re: assigning pointer to NULL
- Index(es):
Relevant Pages
|
|