From 2498407270230315642
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,176c9dc06a6729eb
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-03-24 15:55:06 PST
Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!telocity-west!TELOCITY!fr.clara.net!heighliner.fr.clara.net!news.mailgate.org!newsfeed.icl.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: Pete Becker <petebecker@acm.org>
Newsgroups: comp.std.c++
Subject: Re: why doesn't delete NULL the pointer?
Date: Sun, 24 Mar 2002 23:54:50 GMT
Organization: Dinkumware, Ltd
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3C9E5A54.12B15FB3@acm.org>
References: <a7j7vg$78s$1@watserv3.uwaterloo.ca> <3C9DD892.94860335@acm.org> <a7lhfq$co1$1@eeyore.INS.cwru.edu>
X-Trace: mail2news.demon.co.uk 1017014096 mail2news:13067 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)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Date: 24 Mar 2002 22:59:31 GMT
X-Accept-Language:  en
Lines: 40
Xref: archiver1.google.com comp.std.c++:10159

Ken Alverson wrote:
> 
> "Pete Becker" <petebecker@acm.org> wrote in message
> news:3C9DD892.94860335@acm.org...
> > Pedro Sam wrote:
> > >
> > > 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 ).
> > >
> >
> > void f()
> > {
> > int *ip = new int;
> > delete ip; // no point in setting to null:
> > // goes out of scope immediately
> > }
> 
> Red herring...sure there's no point in that case, but that's easily taken
> care of by the optimizer...

Red herring. You don't write useless code just because you think the
compiler will get rid of it. The point was that setting the pointer to
null often doesn't accomplish anything, which may not have occurred to
the original poster.

-- 
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ 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                ]



