comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Access types as parameters
Date: Fri, 17 Jul 2009 08:03:29 -0700 (PDT)
Date: 2009-07-17T08:03:29-07:00	[thread overview]
Message-ID: <a245c71e-8f1b-47be-a8f4-2ebb2170f9e5@c29g2000yqd.googlegroups.com> (raw)
In-Reply-To: 521c4843-d40f-4545-9e80-ca725e847090@h21g2000yqa.googlegroups.com

On Jul 17, 1:39 am, Rick <rickdu...@gmail.com> wrote:
> Given:
>
>    type My_Type is  ...;
> and
>    type My_Access_Type is access all My_Type'Class;
>
> what is the practical difference between:
>
>    function My_Function (Thing : access My_Type'Class) return
> Positive;
> and
>    function My_Function (Thing : My Access_Type return Positive;

The accessibility level rules say that a value of type My_Access_Type
cannot point to an object that might go away before My_Access_Type
does.  (Unless you use 'Unchecked_Access to create the access value.)
This is to prevent dangling references.  The rules apply to parameters
also, so if you call the second My_Function, you can't give it the
'Access of an object that is deeper than My_Access_Type.  If
My_Access_Type is declared at library level (i.e. in a library
package, not inside a procedure or function), then you can't say

   procedure Some_Procedure is
        X : aliased My_Type;  --or some type derived from My_Type
   begin
        My_Function (X'access);  -- i.e. the second My_Function

But this restriction doesn't apply to the first My_Function.  Since
that My_Function has an access parameter, you can pass the 'Access of
any object of the right type, no matter how deeply nested inside
procedures the object is.

                                    -- Adam



  reply	other threads:[~2009-07-17 15:03 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-17  8:39 Access types as parameters Rick
2009-07-17 15:03 ` Adam Beneschan [this message]
2009-07-17 16:28   ` Hibou57 (Yannick Duchêne)
2009-07-17 23:25     ` rickduley
2009-07-18  1:03       ` Randy Brukardt
2009-07-19 22:57         ` rickduley
2009-07-20  0:10           ` John B. Matthews
2009-07-20  8:13           ` Dmitry A. Kazakov
2009-07-21  0:34           ` Randy Brukardt
2009-07-21 14:34           ` Adam Beneschan
2009-07-23  2:11             ` Stephen Leake
2009-08-11 23:41               ` Randy Brukardt
2009-08-12  2:22                 ` Stephen Leake
2009-08-13  1:06                   ` Randy Brukardt
2009-08-13  8:34                     ` Niklas Holsti
2009-08-13  9:15                       ` Dmitry A. Kazakov
2009-08-13 20:13                         ` Niklas Holsti
2009-08-13 21:07                           ` Dmitry A. Kazakov
2009-08-14  9:27                             ` Niklas Holsti
2009-08-14 10:36                               ` Dmitry A. Kazakov
2009-08-14 16:03                                 ` Niklas Holsti
2009-08-15  9:47                                   ` Dmitry A. Kazakov
2009-08-15 19:19                                     ` Niklas Holsti
2009-08-16  8:32                                       ` Dmitry A. Kazakov
2009-08-16  9:52                                         ` Niklas Holsti
2009-08-16 12:38                                           ` Dmitry A. Kazakov
2009-08-16 13:21                                             ` Niklas Holsti
2009-08-16 17:58                                               ` Dmitry A. Kazakov
2009-08-14  4:07                       ` Randy Brukardt
2009-08-14 10:22                         ` Niklas Holsti
2009-08-18 12:22                     ` Stephen Leake
replies disabled

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