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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.36.36.150 with SMTP id f144mr8752073ita.0.1465182732179; Sun, 05 Jun 2016 20:12:12 -0700 (PDT) X-Received: by 10.157.56.116 with SMTP id r49mr160349otd.19.1465182732036; Sun, 05 Jun 2016 20:12:12 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!p34no3149339qgp.1!news-out.google.com!107ni264qgx.1!nntp.google.com!p34no3149338qgp.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 5 Jun 2016 20:12:11 -0700 (PDT) In-Reply-To: <8af002bb-271a-4a76-b0db-097a3724f0b3@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8202:8510:5985:2c17:9409:aa9c; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8202:8510:5985:2c17:9409:aa9c References: <8af002bb-271a-4a76-b0db-097a3724f0b3@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Avoiding dispatching in procedure's with classwide types From: rieachus@comcast.net Injection-Date: Mon, 06 Jun 2016 03:12:12 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 2958 X-Received-Body-CRC: 2175605755 Xref: news.eternal-september.org comp.lang.ada:30626 Date: 2016-06-05T20:12:11-07:00 List-Id: 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 c= lasswide 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), ther= e 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; =20 with P; package Q is=20 type Bar is new P.Foo with ...; -- Bar has a procedure Put and a function Get. end Q; Temp_Foo: P.Foo :=3D P.Get; Barf: Q.Bar :=3D Temp_Foo; begin=20 Put(Foo(Barf)); The only way you could do something like what you are proposing is to inste= ad of using an operation of a class wide type, do a type conversion to the = parent type, and call its operation: Fooc: Foo'Class :=3D Get; begin Put(Fooc); -- normal Put(Foo(Fooc)); If the descendants of Foo add no new fields, the two calls will be equivale= nt. 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. Wh= y 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 v= ariable of type Foo. Also notice that you may have to use declare blocks t= o create objects of indefinite sizes.