From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,80e74153f40106ab X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-09 01:21:54 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news-out.visi.com!hermes.visi.com!nycmny1-snh1.gtei.net!news.gtei.net!newsfeed.mathworks.com!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Weird controlled behavior - Gnat 3.15p NT Date: Tue, 09 Sep 2003 10:22:26 +0200 Message-ID: <592rlv0pak1cghri31iueh0mm144hv8kpm@4ax.com> References: <5d6fdb61.0309040725.3403aa29@posting.google.com> <3F57B071.5030206@attbi.com> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1063095299 20686565 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:42309 Date: 2003-09-09T10:22:26+02:00 List-Id: On Tue, 09 Sep 2003 02:01:57 GMT, Hyman Rosen wrote: >Robert I. Eachus wrote: > > there are a number of situations where even a limited object > > may be finalized several times > >It's important to point this out to new Ada programmers who are >coming from C++, since this is a major difference in the languages. >In C++, an object's constructor and destructor are called exactly >once, so an object never needs to keep track internally if it has >been initialized or finalized. Really? What about this: class Foo { public : void Surprise () { this->Foo::~Foo (); } virtual ~Foo (); }; You might say that the above is rubbish. Not at all. It is a design pattern for self-destructing objects. For instance when you encapsulate a window to an object which destroys itself upon closing the window. Now imagine what should happen if somebody would allocate Foo on the stack? Access violation. Another example is when an object is put into DLL in a shared section. Then it will be constructed over an over again, each time a new process maps the DLL. And not surprisingly it will be also destructed many many times. A nice feature to fight with. --- Both Ada and C++ have this nasty problem, namely, an ability to explicitly call parts of constructors / destructors. It is a nightmare for a software designer. But there are many reasons why it was made so. Some of them are not very convincing (to me). Future generations of OO languages will hopefully solve this better. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de