Article View: comp.std.c++
Article #3786Re: Referencing pointers after delete
From: John Bain
Date: Sat, 23 Mar 1996 17:09
Date: Sat, 23 Mar 1996 17:09
50 lines
2270 bytes
2270 bytes
"joe (j.) halpin" <jhalpin@bnr.ca> wrote:
>In 3.7.3.2.4 the January working paper says:
>
>4 A deallocation function can free the storage referenced by the pointer
> given as its argument and renders the pointer invalid. The storage
> can be made available for further allocation. An invalid pointer con-
> tains an unusable value: it cannot even be used in an expression.
I interpret this as meaning the _value_ of the pointer cannot be used in
an expression.
>
>This sounds as though, in the following:
>
>char *pc = new char[128];
>delete pc;
^^^^
delete[] pc;
>pc = 0;
>
>it makes the final assignment (an expression) invalid.
The value of the pointer is not used in the expression, so it's OK.
>In fact, it sounds like it also rules out things like 'if(pc == 0)
>...' after the above fragment.
After the final assignment, the pointer's value is no longer invalid, so
it can be used (though obviously not dereferenced while NULL).
By my interpretation, (pc == 0) would, however, be invalid after the
delete but before the assignment of 0.
Cheers,
John
-----------------------------------------------------------------
John Bain
johnb@pivotal-dm.ccmail.compuserve.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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Technical Details
Message-ID:
<315274d1.8486150@dub-news-svc-3.compuserve.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!usenetReferences:
<4is05t$ceo@engnews1.Eng.Sun.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!usenet From: johnb@pivotal-dm.ccmail.compuserve.com (John Bain) Newsgroups: comp.std.c++ Subject: Re: Referencing pointers after delete Date: 23 Mar 1996 17:09:03 GMT Organization: Pivotal Technologies Ltd. Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <315274d1.8486150@dub-news-svc-3.compuserve.com> References: <4is05t$ceo@engnews1.Eng.Sun.COM> NNTP-Posting-Host: taumet.eng.sun.com X-Nntp-Posting-Host: hd62-202.compuserve.com X-Newsreader: Forte Agent .99d/32.182 Content-Length: 1280