"Duane Hebert" <sp**@flarn2.com> wrote in message
news:nC*******************@weber.videotron.net...
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:MC******************@newsread2.news.pas.earth link.net...
"s" <yo*********@home.with.yourself> wrote in message
news:40***************@home.with.yourself... Regarding the following pseudocode:
<pseudocode>
char *buffer = new char[10];
//put some values in buffer
if( some_condition )
{
char *temp = new char[10];
//put some values in temp
delete[] buffer;
buffer = temp;
temp = NULL;
}
//continue doing stuff with buffer
</pseudocode>
Question:
Is the "temp = NULL;" statement necessary?
No. (However it might be useful for testing purposes).
Or preventing possible delete from the wrong pointer.
That's still a 'test' (delegated to operator 'delete').
But assigning NULL blindly for that only purpose imo
is poor practice. One could easily be doing such a
'safe' delete, but leaving something else 'undeleted'
which should have been, possibly having it 'bite' you
later (e.g. assigning a new value to a pointer that's
still pointing to allocated storage.)
-Mike