Re: General method for dynamically allocating memory for a string
- From: Ben Pfaff <blp@xxxxxxxxxxxxxxx>
- Date: Thu, 31 Aug 2006 09:25:04 -0700
rlb@xxxxxxxxxxxxxxxxxxxxxx (Richard Bos) writes:
Frederick Gotham <fgothamNO@xxxxxxxx> wrote:
Randall posted:
if( str2 != NULL ) {
printf( "str2: %s\n", str2 );
} else {
// Setting a null pointer to zero ensures you
// can delete it more than once (free) without
// undefined behavior. This is a good
// programming habit.
str2 = 0;
}
As Richard Heathfield pointed out, both "else" clauses are redundant.
The reasoning given in the comment is also bogus. It is a very _bad_
programming habit to start expecting that you can free pointers twice.
You can free a null pointer any number of times you like. I
think that is what the "it" in "delete it more than once" means.
--
"C has its problems, but a language designed from scratch would have some too,
and we know C's problems."
--Bjarne Stroustrup
.
- References:
- Re: General method for dynamically allocating memory for a string
- From: Frederick Gotham
- Re: General method for dynamically allocating memory for a string
- From: Randall
- Re: General method for dynamically allocating memory for a string
- From: Frederick Gotham
- Re: General method for dynamically allocating memory for a string
- From: Richard Bos
- Re: General method for dynamically allocating memory for a string
- Prev by Date: Re: how could I write this cpp macro
- Next by Date: Re: Holidays are over
- Previous by thread: Re: General method for dynamically allocating memory for a string
- Next by thread: Re: General method for dynamically allocating memory for a string
- Index(es):
Relevant Pages
|