From 2882872195066196353 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,176c9dc06a6729eb X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2002-03-25 11:28:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: "Richard Smith" Newsgroups: comp.std.c++ Subject: Re: why doesn't delete NULL the pointer? Date: Mon, 25 Mar 2002 19:27:35 GMT Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: <1017069849.2635.0.nnrp-01.3e31d362@news.demon.co.uk> References: X-Trace: mail2news.demon.co.uk 1017084461 mail2news:24124 mail2news mail2news.demon.co.uk X-Complaints-To: abuse@demon.net X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Lines: 48 Xref: archiver1.google.com comp.std.c++:10175 "Pedro Sam" wrote in message news:a7j7vg$78s$1@watserv3.uwaterloo.ca... > Hi all, > > I'm curious about the delete operator and NULL pointers. Why doesn't > the standard require that the delete operator to set the pointer's value > to NULL? > > If the pointer is NULL, then if someone comes along and try to access > that pointer, it would crash with a segfault, instead of reading garbage > ( or even worse, write over some memory ). Consider the following example: class bar { /* ... */ }; class foo { public: ~foo() { for( set::set< bar * >::iterator i( s.begin() ); i != s.end(); ++i ) delete *i; } private: std::set< bar * > s; }; i) std::set's iterators are all const_iterators -- even the one named 'iterator' so you cannot modifiy the value. ii) if you did nullify the iterators value (using, say, a const_cast) bad things would happen because the set would have been tricked into containing multiple equal values. -- Richard Smith --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.research.att.com/~austern/csc/faq.html ]