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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6401faa712588412 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-17 09:23:27 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!newsfeed1.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Sender: David Brown From: David Brown Subject: Re: Access to tagged type parameters Newsgroups: comp.lang.ada References: <9lje36$ijn$1@houston.jhuapl.edu> User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (Linux/2.4.4-xfs (i686)) Message-ID: Date: Fri, 17 Aug 2001 16:23:49 GMT NNTP-Posting-Host: 64.133.74.64 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 998065429 64.133.74.64 (Fri, 17 Aug 2001 09:23:49 PDT) NNTP-Posting-Date: Fri, 17 Aug 2001 09:23:49 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net X-Received-Date: Fri, 17 Aug 2001 09:20:35 PDT (newsmaster1.prod.itd.earthlink.net) Xref: archiver1.google.com comp.lang.ada:12054 Date: 2001-08-17T16:23:49+00:00 List-Id: Jonathan DeSena 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