Article View: comp.std.c++
Article #1888Re: Why not op delete(void* v&,size_t);?
From: Steve Clamage
Date: Fri, 01 Sep 1995 19:43
Date: Fri, 01 Sep 1995 19:43
35 lines
1596 bytes
1596 bytes
In article 95Sep1110410@physics12.Berkeley.EDU, tblancha@evolving.com (Todd Blanchard) writes:
>This is common in C:
>
>#define free(X) { free(X); X=0; }
>
>You could do something similar in C++ as:
>
>void operator delete (void*& p, size_t s)
>{
> ::delete p;
> p = 0;
>}
>
>but the standard definition is:
>void operator delete(void* p, size_t);
>
>Why is that?
1. The argument to operator delete need not be an lvalue:
T* foo();
...
delete foo();
2. Believing that this approach solves the dangling pointer problem even
in C, is naive, and leads to a false sense of security. The program might
have any number of copies of the pointer which was deleted, and the copies
would still dangle. You have to use a design discipline that keeps track of
who owns the heap object and under what circumstances it is to be deleted.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<427l56$cd7@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<MATT.95Sep1110410@physics12.Berkeley.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 01 Sep 95 19:43:21 GMT Approved: fjh@cs.mu.oz.au Return-Path: <daemon@ncar.UCAR.EDU> From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Why not op delete(void* v&,size_t);? X-Original-Date: 1 Sep 1995 18:58:46 GMT Organization: Sun Microsystems Inc. Message-ID: <427l56$cd7@engnews2.Eng.Sun.COM> References: <MATT.95Sep1110410@physics12.Berkeley.EDU> Reply-To: clamage@Eng.Sun.COM