From 3652168254422930677
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,176c9dc06a6729eb
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-03-25 07:52:08 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!colt.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: "Ken Alverson" <Ken@Alverson.com>
Newsgroups: comp.std.c++
Subject: Re: why doesn't delete NULL the pointer?
Date: Mon, 25 Mar 2002 15:51:51 GMT
Organization: Case Western Reserve University, Cleveland, OH, USA
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <a7mi76$1bl$1@eeyore.INS.cwru.edu>
References: <a7j7vg$78s$1@watserv3.uwaterloo.ca> <3C9DD892.94860335@acm.org> <a7lhfq$co1$1@eeyore.INS.cwru.edu> <3C9E5921.735FEB25@acm.org>
X-Trace: mail2news.demon.co.uk 1017071519 mail2news:22011 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:05:10 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: 61
Xref: archiver1.google.com comp.std.c++:10165

"Pete Becker" <petebecker@acm.org> wrote in message
news:3C9E5921.735FEB25@acm.org...
> Ken Alverson wrote:
> >
> > > void f(int *ip)
> > > {
> > > delete ip; // setting to null would be misleading:
> > > // caller still holds pointer
> > > }
> >
> > This is better, but you could argue that you shouldn't be able to modify
the
> > pointer (and deleting the pointer is arguably modifying it) without a
> > reference, in which case things would still be consistant.
>
> Huh? ip is modifiable. I don't see how references come into this.

Sorry...I didn't quite say what I was thinking, nor was what I was thinking
totally thought through.

I was trying to say that rules could be made that would outlaw such behavior
(example - a pointer parameter must be a const pointer/delete doesn't work
on const pointer).  I wasn't trying to say that that would be a desirable
goal, or even a possible one, without breaking existing code.  I was merely
attempting to play devil's advocate.

> > > Knowing whether a pointer is valid is a matter of design. If your
design
> > > calls for a flag in some cases, then you can use null as that flag.
Most
> > > of the time assigning null is not needed, or downright dangerous.
> >
> > I can't see how it would be *more* dangerous than not setting it to
NULL,
> > but I agree that *relying* on it being NULL would be a bad idea.
> >
>
> Then you do understand how it's *more* dangerous than not setting it to
> null.

That's like saying (for example) a compiler that supports checking the stack
for corruption is more dangerous than one that does not, because people will
stop worrying about buffer overflows, instead relying on the compiler to
catch them.

While that could possibly be true for some, I have a hard time believing the
average error rate would go up due to it.  A few spikes versus a lot of
small dips...

Personally, I recommend smart pointers anyway...most people can't be trusted
with a pointer in the first place.

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                ]



