Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!lll-winken!uunet!mcsun!sunic!tut!tukki!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.lang.c++ Subject: Re: this=this Message-ID: <1277@tukki.jyu.fi> Date: 6 Sep 89 07:38:28 GMT References: <9638@alice.UUCP> <1273@tukki.jyu.fi> Reply-To: markku@jytko.jyu.fi (Markku Sakkinen) SAKKINEN@FINJYU.bitnet (alternative) Organization: University of Jyvaskyla, Finland Lines: 41 In article tk@allegra.att.com (Thomas Kirk) writes: >In article <1273@tukki.jyu.fi> sakkinen@tukki.jyu.fi (Markku Sakkinen) writes: > > What useful purpose can 'this=this' possibly have served even > > in a constructor or destructor? Help against some bug in earlier > > releases of cfront? ... > >no. in constructors of objects that do their own storage >management (that is, by assignment to `this'), it is necessary >that all execution paths through the constructor include the >assignment. such constructors typically check to see whether >the object was allocated on the stack or otherwise; `this=this' >makes sense for objects allocated on the stack. I am familiar with the additional effects of assignments to "this" in C++ versions so far (before 2.0); they are even described in Stroustrup's book. In my paper at ECOOP'88, "On the darker side of C++", I pointed out that the book's definitions about the matter don't work correctly in general with derived classes, and that releases 1.1 and 1.2 of "cfront" in fact did not follow those definitions but made an equally gross error in an opposite direction. It is the special case of 'this=this' that I still cannot see any sense in. Namely, if a constructor or destructor contains _any_ assignment to "this", the translator deduces that it wants to take care of its own memory (de)allocation, and thus does not generate a call to "new" or "delete". Why should there be, in addition to that meaningful assignment to "this", also 'this=this'? Even if it is on a different execution path, it does not accomplish anything there. (This discussion might still have some relevance: there is a lot of old software around, and it will be a long time before everybody gets Release 2.0 or equivalent). Markku Sakkinen Department of Computer Science University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland