comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Why does `Unchecked_Deallocation` need the access type?
Date: Sun, 26 Jul 2015 10:54:23 +0200
Date: 2015-07-26T10:54:23+02:00	[thread overview]
Message-ID: <5d6faxxdsssv.15g7kj5hv86mk$.dlg@40tude.net> (raw)
In-Reply-To: d81befff-eae1-4b0f-9b96-67ebbe48f190@googlegroups.com

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

  reply	other threads:[~2015-07-26  8:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-26  7:11 Why does `Unchecked_Deallocation` need the access type? EGarrulo
2015-07-26  8:54 ` Dmitry A. Kazakov [this message]
2015-07-26 11:16   ` Niklas Holsti
2015-07-27 22:38     ` Jeremiah
2015-07-27 20:20   ` Randy Brukardt
2015-07-28  7:40     ` Dmitry A. Kazakov
2015-07-28 21:25       ` Randy Brukardt
2015-07-29  6:28         ` Dmitry A. Kazakov
2015-07-29 20:47           ` Randy Brukardt
2015-07-30  6:19             ` Dmitry A. Kazakov
replies disabled

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