Topic: Delete this
Author: Mike Davies <mike_davies@noco.demon.co.uk>
Date: 1998/07/18 Raw View
In article <6oobou$35h$1@shell7.ba.best.com>, Nathan Myers
<ncm@nospam.cantrip.org> writes
> Hans Aberg<haberg@REMOVE.matematik.su.se> wrote:
>> Is "delete this" legal in C++?
>> Note: This is not a question whether it is prudent; I just want to know
>>if it is legal.
>
>This was discussed in committee several times. It is absolutely legal.
>
>It was slightly controversial because it means that a certain (IMHO
>not very important) optimization is not permitted.
What optimisation is this ? Enquiring minds want to know !
--
Mike Davies
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1998/07/18 Raw View
ncm@nospam.cantrip.org (Nathan Myers) writes:
|> Hans Aberg<haberg@REMOVE.matematik.su.se> wrote:
|> > Is "delete this" legal in C++?
|> > Note: This is not a question whether it is prudent; I just want to know
|> >if it is legal.
|>
|> This was discussed in committee several times. It is absolutely legal.
|>
|> It was slightly controversial because it means that a certain (IMHO
|> not very important) optimization is not permitted. However, a large
|> amount of code depended (and still depends) on it, which nobody wanted
|> to break.
Just curious, but what optimization?
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient e objet --
-- Beratung in objektorientierter Datenverarbeitung
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/07/18 Raw View
J. Kanze<kanze@gabi-soft.fr> wrote:
>ncm@nospam.cantrip.org (Nathan Myers) writes:
>
>|> Hans Aberg<haberg@REMOVE.matematik.su.se> wrote:
>|> > Is "delete this" legal in C++?
>|>
>|> This was discussed in committee several times. It is absolutely legal.
>|> It was slightly controversial because it means that a certain (IMHO
>|> not very important) optimization is not permitted.
>
>Just curious, but what optimization?
If I remembered, I would have said. IIRC, it had something to do with
returning from virtual functions, and whether (on some implementations)
the caller would need to get and save a value from the vtbl before the
call that would be needed on return, because the value wouldn't be there
later if the virtual function did "delete this". On most systems no
such value is needed anyway.
That's as much as I remember.
--
Nathan Myers
ncm@nospam.cantrip.org http://www.cantrip.org/
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: haberg@REMOVE.matematik.su.se (Hans Aberg)
Date: 1998/07/17 Raw View
Is "delete this" legal in C++? For example, writing code
class DataRef {
unsigned count;
public:
DataRef* shed() // Remove this copy from reference cluster
{ if (count == 0) throw Exception("Shed count 0.");
if (--count == 0) { delete this; return NULL; }
return this; }
};
so that
DataRef* dp = new DataRef(...);
...
dp->shed();
can delete dp at the appropriate time. (In my own code, this is in reality
handled by another class Data with a pointer to the ref count class
DataRef.)
Note: This is not a question whether it is prudent; I just want to know
if it is legal.
Hans Aberg * Anti-spam: Remove "REMOVE." from email address.
* Email: Hans Aberg <mailto:haberg@member.ams.org>
* Home Page: <http://www.matematik.su.se/~haberg/>
* AMS member listing: <http://www.ams.org/cml/>
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/07/17 Raw View
Hans Aberg<haberg@REMOVE.matematik.su.se> wrote:
> Is "delete this" legal in C++?
> Note: This is not a question whether it is prudent; I just want to know
>if it is legal.
This was discussed in committee several times. It is absolutely legal.
It was slightly controversial because it means that a certain (IMHO
not very important) optimization is not permitted. However, a large
amount of code depended (and still depends) on it, which nobody wanted
to break.
--
Nathan Myers
ncm@nospam.cantrip.org http://www.cantrip.org/
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]