🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3760

Using pointers after delete

#3760
From: joe (j.) halpin
Date: Thu, 21 Mar 1996 19:08
36 lines
2153 bytes
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.

This sounds as though, in the following:

char *pc = new char[128];
delete pc;
pc = 0;

it makes the final assignment (an expression) invalid.

Am I misunderstanding something, or is it illegal to zero out pointers
after they've been deallocated? I'm assuming that the intent was to
disallow dereferencing of pointers that have been handed to
delete. The wording seems to disallow the above as well.

In fact, it sounds like it also rules out things like 'if(pc == 0)
...' after the above fragment.

Joe
-- 
Joe Halpin                             jhalpin@nortel.com
Nortel Wireless                        (214) 684-5657 
Richardson, TX  75083-3871             <standard disclaimer applies>
-------------------------------------------------------------------------------
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <4irkhs$8al@crchh327.rich.bnr.ca>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: "joe (j.) halpin" <jhalpin@bnr.ca>
Newsgroups: comp.std.c++
Subject: Using pointers after delete
Date: 21 Mar 1996 11:08:42 PST
Organization: Bell-Northern Research, Richardson, TX
Approved: austern@isolde.mti.sgi.com
Message-ID: <4irkhs$8al@crchh327.rich.bnr.ca>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date:  Thu, 21 Mar 1996 13:11:24 +0000 
Content-Identifier:  Using pointer... 
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMVGpm0y4NqrwXLNJAQGtpgIAgXYveU7qMkMyxwlfi0myt0w5NTDN9qFP
 RL+AcDtiraLG5Gvnj6QZFofuVOyC4kdHyPTm158EIKiQuKiAvGA3YA==
 =0mMj
Originator: austern@isolde.mti.sgi.com