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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Why does `Unchecked_Deallocation` need the access type? Date: Sun, 26 Jul 2015 10:54:23 +0200 Organization: cbb software GmbH Message-ID: <5d6faxxdsssv.15g7kj5hv86mk$.dlg@40tude.net> References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: 5CNUwuQ0q1vZOSDFkeKrYQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:27010 Date: 2015-07-26T10:54:23+02:00 List-Id: On Sun, 26 Jul 2015 00:11:22 -0700 (PDT), EGarrulo wrote: > The `Free` procedure to deallocate an object is declared like this: > > procedure Free is > new Ada.Unchecked_Deallocation(Object_Type, Object_Access_Type); > > Yet the access parameter seems redundant. Why is it necessary to specify it? Because the instance of the generic procedure Free has the argument of the access type: procedure Free (Pointer : in out Object_Access_Type); BTW, in Ada you can have as many access types as you wish. With operations (like Free) of their own. It is sometimes very useful: type Aphabetic_Ptr is access all String; function "=" (Left, Right : Aphabetic_Ptr) return Boolean; function "<" (Left, Right : Aphabetic_Ptr) return Boolean; type Lexicographical_Ptr is access all String; function "=" (Left, Right : Lexicographical_Ptr) return Boolean; function "<" (Left, Right : Lexicographical_Ptr) return Boolean; Then you create two indices of the same set of strings using different sort ordering. What is indeed redundant here is the Object_Type. It is necessary because Ada does not have access type introspection. That is, you cannot get the object type from an access type, though the compiler knows it anyway. Surely there should have been an attribute to get that type, e.g. Pointer_Type'Target But there is none. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de