comp.lang.ada
 help / color / mirror / Atom feed
From: rieachus@comcast.net
Subject: Re: Avoiding dispatching in procedure's with classwide types
Date: Sun, 5 Jun 2016 20:12:11 -0700 (PDT)
Date: 2016-06-05T20:12:11-07:00	[thread overview]
Message-ID: <cc67e889-5c28-4f5d-bafa-35ce766b48dd@googlegroups.com> (raw)
In-Reply-To: <8af002bb-271a-4a76-b0db-097a3724f0b3@googlegroups.com>

On Saturday, May 28, 2016 at 3:01:37 PM UTC-4, Jeremiah wrote:
> I have a procedure that uses one tagged type (the primitive type) and a classwide type.

1) I have no clue as to what you are trying to do here.
2) I have no idea why you think that this would improve performance.

If you have a subroutine with a parameter of a class wide type (Foo'Class), dispatching happens.  If you have a parameter of the base type (Foo), there is no dispatching, however there may be inheritance. If a subprogram of a type is declared in the same package spec as the type, you get inheritance.  So:

  package P is
    type Foo is private;
    procedure Put(F: in out Foo);
    function Get return Foo;
  ...
  end P;
 
  with P;
  package Q is 
    type Bar is new P.Foo with ...;
    -- Bar has a procedure Put and a function Get.
  end Q;


   Temp_Foo: P.Foo := P.Get;
   Barf: Q.Bar := Temp_Foo;
 begin 
   Put(Foo(Barf));

The only way you could do something like what you are proposing is to instead of using an operation of a class wide type, do a type conversion to the parent type, and call its operation:

  Fooc: Foo'Class := Get;
begin
  Put(Fooc);  -- normal
  Put(Foo(Fooc));

If the descendants of Foo add no new fields, the two calls will be equivalent.  If Bar or other descendants add state, that state will be stripped off in the bottom call to Put, and you will get the Put of Foo not of Bar.  Why you would want to bake such trouble in a program is beyond me.

Notice the extra effort to be able to call Get and assign the result to a variable of type Foo.  Also notice that you may have to use declare blocks to create objects of indefinite sizes.


  reply	other threads:[~2016-06-06  3:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-28 19:01 Avoiding dispatching in procedure's with classwide types Jeremiah
2016-06-06  3:12 ` rieachus [this message]
2016-06-07  2:23   ` Jeremiah
2016-06-07  7:43     ` Dmitry A. Kazakov
2016-06-07 11:30       ` Jeremiah
2016-06-07 21:05         ` Randy Brukardt
2016-06-09  1:12           ` Jeremiah
2016-06-06  3:24 ` rieachus
replies disabled

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