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!mx02.eternal-september.org!feeder.eternal-september.org!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Why does `Unchecked_Deallocation` need the access type? Date: Sun, 26 Jul 2015 14:16:49 +0300 Organization: Tidorum Ltd Message-ID: References: <5d6faxxdsssv.15g7kj5hv86mk$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net mM8DC3wx7xyu+koH9xv9jgF7ubNDCEhX+5JBATzRdR56Jy04mH Cancel-Lock: sha1:JbqshJLHgauG2ZoUrw6pZdsvy2k= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: <5d6faxxdsssv.15g7kj5hv86mk$.dlg@40tude.net> Xref: news.eternal-september.org comp.lang.ada:27013 Date: 2015-07-26T14:16:49+03:00 List-Id: On 15-07-26 11:54 , Dmitry A. Kazakov wrote: > 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); [snip] > 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. Another reason, perhaps a trivial one, for including Object_Type is that the only syntax to define a formal access type in a generic declaration uses an access_type_definition, which requires a name for the object type. The declaration of Unchecked_Deallocation (RM 12.5.4) has this form: generic type Object(<>) is limited private; type Name is access Object; procedure Ada.Unchecked_Deallocation(X : in out Name) ... Ada could perhaps have allowed a formal_access_type_definition with an unnamed target type, perhaps of the form type Name is access; -- Not Ada! or type Name is access <>; -- Not Ada! and then the Object formal type could have been omitted from Unchecked_Deallocation. However, it seems to me that such formal access types would not be very useful without the 'Target attribute that Dmitry suggested. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .