From -4102940952736286857
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,176c9dc06a6729eb
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-04-05 08:50:05 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: David Schwartz <davids@webmaster.com>
Newsgroups: comp.std.c++
Subject: Re: why doesn't delete NULL the pointer?
Date: Fri,  5 Apr 2002 16:49:47 GMT
Organization: WebMaster Incorporated
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3CADD3C8.EDA111C6@webmaster.com>
References: <a7j7vg$78s$1@watserv3.uwaterloo.ca> <3C9DD892.94860335@acm.org> <a7lhfq$co1$1@eeyore.INS.cwru.edu> <3C9E5921.735FEB25@acm.org> <a7mi76$1bl$1@eeyore.INS.cwru.edu> <3CA063FF.3C2EE83A@acm.org> <a7qsk8$81n$1@eeyore.INS.cwru.edu> <3CA0FD94.A13F8343@acm.org> <a7r75i$ndi$1@eeyore.INS.cwru.edu> <3CA26183.B5822E43@acm.org> <a813uq$dbj$1@eeyore.INS.cwru.edu>
X-Trace: mail2news.demon.co.uk 1018025392 mail2news:25022 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: Fri, 5 Apr 2002 16:41:45 +0000 (UTC)
X-Accept-Language: en
Lines: 64
Xref: archiver1.google.com comp.std.c++:10405

Ken Alverson wrote:

> I still feel my analogy is valid, but this really isn't going anywhere, so
> I'll drop the issue.
> 
> Ken

	So what do you do if the value of the pointer is still needed?!

Consider the following code:

Mutex mutex_table[256];

void LockMutex(void *p)
{
 mutex_table[reinterpret_cast<unsigned int>(p)%256].Lock();
}

void UnlockMutex(void *p)
{
 mutex_table[reinterpret_cast<unsigned int>(p)%256].Unlock();
}

void ConditionalLockedDelete(Foo *p)
{
 LockMutex(p);
 if(p->ShouldDelete()) delete p;
 UnlockMutex(p);
}

	How would this work if 'delete' NULLed the pointer? Here's another
case:

class Foo
{
 protected:
 Foo *brother;
 bool can_delete;
 public:
 static bool Detach(Foo *a)
 {
  if(can_delete) { delete a; return true; }
  return false;
 }
 void BrotherNowGone(void) { brother=NULL; }
 Foo *GetBrother() { return brother; }
}

void DetachAndDeLink(Foo *a, Foo *b)
{
 bool did_delete=a->Detach();
 if(did_delete && (b->GetBrother()==a)) b->BrotherNowGone();
}

	How would this work if 'delete' NULLed the pointer?

	DS

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]



