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-Thread: a07f3367d7,7ff1de84a8945e80 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!c29g2000yqd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Access types as parameters Date: Fri, 17 Jul 2009 08:03:29 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <521c4843-d40f-4545-9e80-ca725e847090@h21g2000yqa.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1247843009 14155 127.0.0.1 (17 Jul 2009 15:03:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 17 Jul 2009 15:03:29 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c29g2000yqd.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7112 Date: 2009-07-17T08:03:29-07:00 List-Id: On Jul 17, 1:39=A0am, Rick wrote: > Given: > > =A0 =A0type My_Type is =A0...; > and > =A0 =A0type My_Access_Type is access all My_Type'Class; > > what is the practical difference between: > > =A0 =A0function My_Function (Thing : access My_Type'Class) return > Positive; > and > =A0 =A0function 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