comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov)
Subject: Re: Merits of re-dispatching [LONG]
Date: Fri, 08 Feb 2002 09:16:32 GMT
Date: 2002-02-08T09:16:32+00:00	[thread overview]
Message-ID: <3c6392e8.2400843@News.CIS.DFN.DE> (raw)
In-Reply-To: u66a74idn9n084@corp.supernews.com

On Thu, 7 Feb 2002 20:29:42 -0500, "Matthew Heaney" <mheaney@on2.com>
wrote:

>"Hyman Rosen" <hyrosen@mail.com> wrote in message
>news:1013094178.985786@master.nyc.kbcfp.com...
>> Again, this is false for C++. In a C++ constructor or destructor, the
>> type of the object is the type of the class of which the constructor or
>> destructor is a member. So in the C++ equivalent of Finalize(A), the
>> call to Foo(A'Class) would call Foo(A), not Foo(AA), because in
>> the destructor of A, the object is an A, not an AA, even when we
>> are destructing the A component of an AA. This is good, since, as
>> you point out, the AA part is no longer there!
>
>Yes, that's true, but it's easy to think that the virtual member function
>call will dispatch, because that's how it works for every other virtual
>member function:
>
>class B
>{
>public:
>   virtual ~B();
>   virtual void f();
>   virtual void g();
>};
>
>void B::f()
>{
>   g();  //dispatches
>}
>
>B::~B()
>{
>   g();  //does not dispatch
>}
>
>You have to learn that the call to g() doesn't dispatch in the dtor.  This
>behavior is certainly not immediately obvious, especially for those new to
>the language.
>
>You seemed to have missed the point about this error-prone feature of C++: a
>naive programmer is going to depend on dispatching to occur.  He has to
>learn --the hard way-- that the dtor is special.

Yes, but there are two things here.

First C++ does not make any difference between class wide and specific
objects. The same type B is a class wide in B::f () and specific in
B::~B (). So the difference in how B::f and B::~B are dealing with
calls to g(). This is IMO bad.

Second. The behaviour of B::~B is safe. One should never expect
dispatching in a specific subroutine like destructor. My point is that
the language should prohibit dispatching from specific subroutines.
Therefore in my opinion the behaviour of B::f is unsafe. It is
declared as virtual (dispatching) which means that inside B::f the
type is already *known*. Thus there is no need in [re-]dispatching. A
call to g() can be statically resolved.

The reason why C++ dispatches in B::f (), is that otherwise it would
impossible to have class wide subroutines [see the point 1]. In
contrary to this Ada 95 does have class wide routines, so my question,
why [explicit] re-dispatching is supported in Ada 95?

Regards,
Dmitry Kazakov



  reply	other threads:[~2002-02-08  9:16 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-07 10:26 Merits of re-dispatching [LONG] Dmitry A. Kazakov
2002-02-07 15:03 ` Hyman Rosen
2002-02-08  1:29   ` Matthew Heaney
2002-02-08  9:16     ` Dmitry A. Kazakov [this message]
2002-02-08 18:30       ` Hyman Rosen
2002-02-09  0:10         ` Matthew Heaney
2002-02-12  8:32         ` Dmitry A. Kazakov
2002-02-12 21:37           ` Hyman Rosen
2002-02-13  9:29             ` Dmitry A. Kazakov
2002-02-13 14:32               ` Hyman Rosen
2002-02-13 19:58           ` Dave Harris
2002-02-14 15:06             ` Dmitry A. Kazakov
2002-02-16 12:10               ` Dave Harris
2002-02-18  8:57                 ` Dmitry A. Kazakov
2002-02-18 19:47                   ` Merits of re-dispatching Dave Harris
2002-02-19  9:20                     ` Dmitry A. Kazakov
2002-02-21  5:49                       ` Hyman Rosen
2002-02-21  9:04                         ` Dmitry A. Kazakov
2002-02-21 18:17                           ` Hyman Rosen
2002-02-22  9:21                             ` Dmitry A. Kazakov
2002-02-22 16:59                               ` Hyman Rosen
2002-02-25  8:51                                 ` Dmitry A. Kazakov
2002-02-08 23:51       ` Merits of re-dispatching [LONG] Matthew Heaney
2002-02-12  9:02         ` Dmitry A. Kazakov
2002-02-07 23:40 ` Nick Roberts
2002-02-08  8:56   ` Dmitry A. Kazakov
2002-02-08  1:06 ` Matthew Heaney
2002-02-08  9:48   ` Dmitry A. Kazakov
2002-02-09  0:16     ` Matthew Heaney
2002-02-08 18:10   ` Hyman Rosen
2002-02-09  0:41     ` Matthew Heaney
2002-02-08 18:33 ` Nick Roberts
2002-02-09  4:07   ` Nick Roberts
2002-02-12 10:13   ` Dmitry A. Kazakov
2002-02-14 20:57 ` Tucker Taft
2002-02-15 15:43   ` Dmitry A. Kazakov
replies disabled

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