comp.lang.ada
 help / color / mirror / Atom feed
From: David Brown <gnatlist@davidb.org>
Subject: Re: Access to tagged type parameters
Date: Fri, 17 Aug 2001 16:23:49 GMT
Date: 2001-08-17T16:23:49+00:00	[thread overview]
Message-ID: <pybf7.17453$ZM2.1548231@newsread2.prod.itd.earthlink.net> (raw)
In-Reply-To: 9lje36$ijn$1@houston.jhuapl.edu

Jonathan DeSena <jonathan.desena@jhuapl.edu> wrote:

> "All formal parameters belonging to tagged 
> types are implicitly declared to be aliased. This allows a subprogram to 
> create access values pointing to its tagged formal parameters using the 
> 'Access attribute ..." (section 12.6.2, page 579 in my version)
> 
> non-local pointer cannot point to local object

>      B_Access: A_Access_Type;

The pointer access type A_Access_Type has a scope outside of the scope of
the object you getting the access value of.  If you use 'Unchecked_Access,
you will get the access you want, however, the it is up to you to make sure
it doesn't go outside of scope.

This access can easily be used to call procedures/functions that take
access parameters.  Since access parameters cannot be assigned (without
conversions) to access types, the object can only be accessed within that
procedure/function.

Here is your example modified to use an access type:

-------------------------
with Ada.Text_IO;
procedure Test is

   type A_Type is tagged record
      A1:Integer; --just to fill the record with something
      A2:Integer;
   end record;
   type A_Access_type is access all A_Type'Class;

   procedure Access_Arg (AC : access A_Type'Class) is
   begin
      null;
   end Access_Arg;

   procedure A_Test (B:in out A_Type'Class) is
   begin
      Access_Arg (B'Access);
      Ada.Text_IO.Put_Line("Done.");
   end A_Test;

   C:A_Type;
begin
   A_Test(C);
end Test;
-------------------------

--
David Brown



  reply	other threads:[~2001-08-17 16:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-17  9:16 Access to tagged type parameters Jonathan DeSena
2001-08-17 16:23 ` David Brown [this message]
2001-08-17 19:26   ` Ted Dennison
2001-08-17 13:55     ` Jonathan DeSena
2001-08-17 21:51       ` Ted Dennison
2001-08-20 14:03         ` Jonathan DeSena
2001-08-17 21:45 ` tmoran
replies disabled

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