comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: What makes a procedure call 'dispatching' in Ada?
Date: Fri, 20 Nov 2009 15:10:05 +0100
Date: 2009-11-20T15:10:05+01:00	[thread overview]
Message-ID: <hjt17s3h92og.k8binujh5yyo$.dlg@40tude.net> (raw)
In-Reply-To: he66eh$fpl$1@nntp.ilk.net

On Fri, 20 Nov 2009 14:43:45 +0100, Markus Schoepflin wrote:

> So If I understand this correctly, if I want dispatching to happen on a 
> given type, I always need to use the class type?

Exactly.

This helps both the compiler to make the program much more efficient by
eliminating unnecessary dispatch and you indicating the design problems
like this and making it safer in the opposite cases:

Consider the case where one non-abstract operation calls another:

    type FOO is abstract tagged null record;
    procedure P (THIS : in out FOO);
    procedure A (THIS : in out FOO);

...
    procedure P (THIS : in FOO) is
    begin
        ...
        A (THIS);
           -- This is a part of the implementation of P for the type FOO
        ...
    end P;

Here the call to A does not dispatch. In other language like C++ it would.

Now consider a type derived from FOO, that overrides A, but inherits P.
That could break the implementation of P in C++, but not in Ada, where P
will behave exactly as it did before.

When you design P you should decide whether it is a class-wide subprogram
or not. That role of P will define the behavior of calls to A from its
body. Sometimes the compiler can detect that the declared role of P does
not match its implementation, as it was in your case.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2009-11-20 14:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-20 13:15 What makes a procedure call 'dispatching' in Ada? Markus Schoepflin
2009-11-20  9:31 ` stefan-lucks
2009-11-20 14:10   ` Niklas Holsti
2009-11-20 13:27 ` Dmitry A. Kazakov
2009-11-20 13:43   ` Markus Schoepflin
2009-11-20 13:54     ` RasikaSrinivasan@gmail.com
2009-11-20 13:58     ` Markus Schoepflin
2009-11-20 14:19       ` Niklas Holsti
2009-11-21 14:07       ` Peter C. Chapin
2009-11-20 14:00     ` Niklas Holsti
2009-11-20 14:10     ` Dmitry A. Kazakov [this message]
2009-11-20 13:56 ` Niklas Holsti
2009-11-20 14:31   ` Dmitry A. Kazakov
2009-11-20 15:00     ` Niklas Holsti
2009-11-20 18:44       ` Dmitry A. Kazakov
2009-11-20 20:09         ` Niklas Holsti
2009-11-20 20:59           ` Dmitry A. Kazakov
2009-11-20 14:54 ` Ludovic Brenta
replies disabled

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