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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada Annoyances Date: Fri, 23 Jun 2017 18:10:58 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <1ac5a44b-4423-443a-a7bb-2864d9abe78f@googlegroups.com> <1498048151.20885.28.camel@obry.net> <96174ea5-852d-44e9-8535-7c1eb24d5326@googlegroups.com> <8d3aff06-82df-485f-89e5-a50c326aab05@googlegroups.com> NNTP-Posting-Host: MajGvm9MbNtGBKE7r8NgYA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:47082 Date: 2017-06-23T18:10:58+02:00 List-Id: On 2017-06-23 17:23, raph.amiard@gmail.com wrote: > Well that's really a strange way to put it: > > 1. In Ada you dispatch via going through the class wide type But if > you do, then your call *will* go through a virtual table. If that is a primitive operation, then it does, if it is a class-wide operation it does not. > 2. In C++ only virtual methods dispatch and go through the virtual > table. The penalty on the type is exactly the same (by-ref passing and tag) Same in Ada. Non-primitive operations do not dispatch. Semantically there is no difference. There are operations defined on the whole class ("virtual operations") and operations defined on a specific type. The operations defined on the whole class are further subdivided into: 1. Dispatching operations implemented in a way that each specific instance of the class has a separate operation body. Dispatching is an act of selecting that body according to the actual specific type the class-wide object holds. 2. Class-wide operations that have one body for all instances of the class. > 3. The ONLY thing that differs is the granularity of how you choose > to dispatch or not. In C++, this choice is made by the method's > implementer. In Ada, it is made at the call-site by every caller. It is not granularity it is untyped in C++ vs. typed in Ada. As I said it is quite possible in Ada to declare a type-specific operation for a tagged type. That is, an operation defined on this concrete type only and undefined on other instances from the class. Usually it is used in the package bodies: package P is type T is tagged ... end P; package body P is procedure Internal (X : in out T) is -- This does not dispatch begin ... end Internal; end P; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de