From -4354159329734080178 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,176c9dc06a6729eb X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2002-03-25 07:53:02 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!newspump.sol.net!newsfeed.cwix.com!newsfeed.icl.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: "Ken Alverson" Newsgroups: comp.std.c++ Subject: Re: why doesn't delete NULL the pointer? Date: Mon, 25 Mar 2002 15:52:13 GMT Organization: Case Western Reserve University, Cleveland, OH, USA Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: References: <3C9DD892.94860335@acm.org> <3C9E5A54.12B15FB3@acm.org> X-Trace: mail2news.demon.co.uk 1017071536 mail2news:22018 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) NNTP-Posting-Date: 25 Mar 2002 07:15:01 GMT NNTP-Posting-User: kla4@dsl-65-186-37-105.telocity.com 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: 40 Xref: archiver1.google.com comp.std.c++:10166 "Pete Becker" wrote in message news:3C9E5A54.12B15FB3@acm.org... > Ken Alverson wrote: > > "Pete Becker" wrote in message > > news:3C9DD892.94860335@acm.org... > > > > > > 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. I do so on a regular basis. I return classes, relying that the return value will be optimized, avoiding a copy construction. I use smart pointers, relying that the function call to operator-> or operator* will be eliminated. I use vectors, relying that iterator access will be inlined to the point where it will be as fast as array access. The point that the result doesn't survive the function is good. It has failed to be useful. But it hasn't actively done harm either. Ken --- [ 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 ]