Topic: Modifying delete() argument


Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Mon, 1 Nov 1993 10:02:37 GMT
Raw View
In article <1993Oct23.020616.3984@news.mentorg.com> robina@wv.mentorg.com (Robin Albrecht) writes:
>The ARM states (5.3.4, p 63) that "if the expression denoting the object
>in a delete expression is a modifiable lvalue, its value is undefined
>after deletion".  It also states that an operator delete() for a class
>X "must have its first argument of type void*", and that "the global
>operator delete() takes a single argument of type void *" (12.5, p 283).
>This being the case, I don't see any way (except for the compiler writer)
>to define operator delete() so that it can modify its argument.  Can this
>be done?

You are correct that there is no way for the "end user" C++ programmer
to write his/her own delete function such that once it is called (and
once it has returned) its argument will definitely be modified.

Note however that regardless of whether or not *you* define your own
operator delete, after evaluation of a delete expression like:

 delete p;

the value of `p' MAY BE MODIFIED.  (If it *is* modified, that will be because
your C++ compiler implementor caused it to be modified... totally independent
of any intentions which you or your delete operator might have had.)

--

-- Ronald F. Guilmette, Sunnyvale, California -------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------




Author: joe@bftsi0.UUCP (Joe Foster of Borg)
Date: 1 Nov 93 00:43:45 GMT
Raw View
In article <1993Oct29.002221.2298@borland.com>, pete@borland.com (Pete Becker) writes:

> >This would allow expressions like:

> >    p = delete p;

>  What does this accomplish that you can't do just as easily with two
> lines of code?

>  delete p;
>  p = 0;

Or a macro:

#define DELETE(p) { delete p; p = (void*)0xDEADBEEF; }

--
Joe Foster (joe@bftsi0.uucp)
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!