Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Avoiding da...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 14 of 16 Topic 9494 of 10094
Post > Topic >>

Re: Avoiding dangling pointers.

by "Andrew Koenig" <ark@[EMAIL PROTECTED] > May 4, 2008 at 05:16 PM

"Thomas Maeder" <maeder@[EMAIL PROTECTED]
> wrote in message
news:m2wsn3ipsx.fsf@[EMAIL PROTECTED]
> Rafael Anschau <rafael.anschau@[EMAIL PROTECTED]
> writes:

>> I read that you should assign null (0) to all pointers that you call
>> delete on.

> My opinion is to replace such pointers by smart pointer objects.

Agreed.

For years, I have been hearing people claim that it's a good idea to set
pointers to zero after deleting them, and the claim has always made me
uncomfortable without my being able to figure out quite why.

A few moments ago, I suddenly realized why this code makes me
uncomfortable:

     delete p;
     p = 0;

How can you test it?  In other words, suppose you forgot to set p to 0. 
How
would you detect the oversight?

So I think my discomfort comes from the notion that it is a good idea to
write code that you intend to behave in a way that's somewhere between
difficult and impossible to test.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 16 Posts in Topic:
Avoiding dangling pointers.
Rafael Anschau <rafael  2008-04-11 15:33:08 
Re: Avoiding dangling pointers.
d04rp@[EMAIL PROTECTED]   2008-04-11 18:06:51 
Re: Avoiding dangling pointers.
Sean Hunt <rideau3@[EM  2008-04-11 18:08:47 
Re: Avoiding dangling pointers.
Francis Glassborow <fr  2008-04-11 18:11:05 
Re: Avoiding dangling pointers.
Rafael Anschau <rafael  2008-04-12 12:08:56 
Re: Avoiding dangling pointers.
"Alf P. Steinbach&qu  2008-04-12 12:09:58 
Re: Avoiding dangling pointers.
Carl Barron <cbarron41  2008-04-12 12:07:12 
Re: Avoiding dangling pointers.
pstallworth@[EMAIL PROTEC  2008-04-12 12:13:11 
Re: Avoiding dangling pointers.
Thomas Maeder <maeder@  2008-04-12 12:13:10 
Re: Avoiding dangling pointers.
Jiri Palecek <jpalecek  2008-04-12 12:13:11 
Re: Avoiding dangling pointers.
Ulrich Eckhardt <eckha  2008-04-14 12:42:42 
Re: Avoiding dangling pointers.
galathaea <galathaea@[  2008-04-14 21:25:34 
Re: Avoiding dangling pointers.
Michiel.Salters@[EMAIL PR  2008-05-02 12:46:39 
Re: Avoiding dangling pointers.
"Andrew Koenig"  2008-05-04 17:16:05 
Re: Avoiding dangling pointers.
Alan McKenney <alan_mc  2008-05-05 07:08:52 
Re: Avoiding dangling pointers.
Andy Champ <no.way@[EM  2008-05-06 18:21:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:01:14 CDT 2008.