Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!tut!tukki!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.lang.c++ Subject: Re: Change to delete is in order Message-ID: <3743@tukki.jyu.fi> Date: 14 Mar 90 07:54:54 GMT References: <5136@odin.SGI.COM> <25FC0210.26173@paris.ics.uci.edu> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) Organization: University of Jyvaskyla, Finland Lines: 37 In article <25FC0210.26173@paris.ics.uci.edu> rfg@ics.uci.edu (Ronald Guilmette) writes: >In article <5136@odin.SGI.COM> shap@delrey.sgi.com (Jonathan Shapiro) writes: >>I believe that a small change to the definition of the delete operator >>is worth considering. The change would have no effect on correct >>programs, but would help find incorrect programs in some circumstances. >> >> delete should be defined to zero the pointer it is handed >> after freeing the associated store. > >That would be a swell idea, except that I don't believe that the value >in a delete statement is required to be an lvalue. What should the compiler >do if the value is *not* an lvalue? Punt? Right: If the delete operator is redefined for a class, then according to the C++ 2.0 Reference Manual it will be like void operator delete (void*) (possibly with a second argument). Thus it only gets a _copy_ of the pointer value. Shapiro's proposal is nevertheless sensible, and would make 'new' and 'delete' more symmetric. The zeroing could be done _if_ the operand is an lvalue. For a redefined delete operator, this could be done _before_ it is actually invoked, but after the destructor (if any) is invoked. Of course one can keep many pointers to a dynamic object, but in the majority of cases in "typical" code there is probably only one pointer to each object, and so zeroing it automatically would help a lot, e.g. prevent trivial errors. Markku Sakkinen Department of Computer Science University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland SAKKINEN@FINJYU.bitnet (alternative network address)