From -5730779610035606022 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,176c9dc06a6729eb X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2002-03-24 06:55:03 PST Return-Path: X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!comp-std-cpp-robomod!not-for-mail X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) From: Marco Manfredini Newsgroups: comp.std.c++ Subject: Re: why doesn't delete NULL the pointer? Organization: Ronco Novelty Products Message-ID: References: X-Orig-NNTP-Posting-Host: pd957c426.dip0.t-ipconnect.de (217.87.196.38) X-Orig-X-Trace: fu-berlin.de 1016978858 23184441 217.87.196.38 (16 [82048]) User-Agent: Xnews/4.06.22 Hamster/1.3.23.1 X-Love-Love-Love-LaLaLove-LaLaLove: Makes-The-World-GoAround. X-Face: O@B=1>:2p=[:e57TJ=;("U%>a^~8N3D%,S^m~W3V%p|Xa}jUf$E0]TR Approved: Fergus Henderson , moderator of comp.std.c++ Date: Sun, 24 Mar 2002 08:51:14 CST Lines: 48 Xref: archiver1.google.com comp.std.c++:10152 p2sam@uwaterloo.ca (Pedro Sam) wrote: > Hi all, > > I'm curious about the delete operator and NULL pointers. Why doesn't > the standard require that the delete operator to set the pointer's value > to NULL? You weren't able to do this anymore: struct A {}; struct X { A * const a; X() : a(new A) { } ~X() { delete a; } }; > > If the pointer is NULL, then if someone comes along and try to access > that pointer, it would crash with a segfault, instead of reading garbage > ( or even worse, write over some memory ). > > Crash early is a Good Thing(TM) right? Accessing a pointer after it has been deleted is a lesser source of errors and it's almost always easy to find. The 'real' kind of error occurs when you access deleted memory through an aliased pointer: The is much harder to track, happens more frequently (at least to the unstructured programmer) and can't be covered by a modifing delete. If you want this kind of delete, define one: template void destroy(T * &t) { delete t; t=NULL; } Marco --- [ 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 ]