comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Weird controlled behavior - Gnat 3.15p NT
Date: Tue, 09 Sep 2003 10:22:26 +0200
Date: 2003-09-09T10:22:26+02:00	[thread overview]
Message-ID: <592rlv0pak1cghri31iueh0mm144hv8kpm@4ax.com> (raw)
In-Reply-To: pwa7b.8484$w41.5873@nwrdny02.gnilink.net

On Tue, 09 Sep 2003 02:01:57 GMT, Hyman Rosen <hyrosen@mail.com>
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



  parent reply	other threads:[~2003-09-09  8:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-04 15:25 Weird controlled behavior - Gnat 3.15p NT Jano
2003-09-04 15:40 ` Martin Krischik
2003-09-04 18:06 ` Patrice Freydiere
2003-09-04 19:03   ` Jano
2003-09-04 20:57     ` Jano
2003-09-05  8:48     ` Preben Randhol
2003-09-05 13:48       ` Jano
2003-09-04 21:36 ` Robert I. Eachus
2003-09-05  4:04   ` Randy Brukardt
2003-09-05 13:48     ` Jano
2003-09-05 14:33       ` Dmitry A. Kazakov
2003-09-09  2:01   ` Hyman Rosen
2003-09-09  7:02     ` Jean-Pierre Rosen
2003-09-11  3:40       ` Hyman Rosen
2003-09-09  8:22     ` Dmitry A. Kazakov [this message]
2003-09-11  3:46       ` Hyman Rosen
2003-09-11  8:23         ` Dmitry A. Kazakov
2003-09-05  7:10 ` Jean-Pierre Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox