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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: How can one record component be local and another not? Date: Wed, 6 May 2020 22:09:40 +0300 Organization: Tidorum Ltd Message-ID: References: <1e054635-6c0a-41ca-8cc2-080aa5f532a3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net 52mzCn8CzaXoFekj3gpd8A43O1H08KqE2lAJaYbVelKjnVbabJ Cancel-Lock: sha1:qpwXp5YImu8jDwnnnNs7L8uFBCY= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 In-Reply-To: <1e054635-6c0a-41ca-8cc2-080aa5f532a3@googlegroups.com> Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:58616 Date: 2020-05-06T22:09:40+03:00 List-Id: On 2020-05-06 21:28, Jere wrote: > On Wednesday, May 6, 2020 at 1:30:58 PM UTC-4, Niklas Holsti wrote: >> On 2020-05-05 20:32, hreba wrote: >>> Ok, with all your hints I came to the following solution: >>> >>> -- >>> package Aux is >>>    type Integer_P is access all Integer; >>>    type Rec is limited record >>>       a: aliased Integer; >>>       p: Integer_P; >>>    end record; >>> >>>    procedure Init (r: access Rec); >>> end Aux; >>> -- >>> package body Aux is >>>    procedure Init (r: access Rec) is >>>    begin >>>       r.p:= r.a'Access; >>>    end Init; >>> end Aux; >>> -- >>> with Aux; >>> procedure Test is >>>    r:    aliased Aux.Rec; >>> begin >>>    Aux.Init (r'Access); >>> end Test; >>> -- >>> >> >> Somewhat surprisingly to me, any call of the form >> "Aux.Init (r'Unchecked_Access)" also works, whether "r" is a >> library-level object or a local (limited-life) object, even if >> "Aux.Init" itself uses "'Access" and not "'Unchecked_Access". Apparently >> the accessibility level provided in the value of Unchecked_Access is >> such as to make the check succeed, as for a library-level object. >> > Yeah, RM section 13.10 says it treats it as if the object were declared > at library level for Unchecked_Access That explains it clearly, thanks for the reference. >> I also found that a call like "Aux.Init (new Aux.Rec)", which applies >> "Aux.Init" to a heap-allocated "Rec" object, fails the accessibility >> check, so this check is really strict. Of course, the heap object can be >> deallocated at any time, so it may have a short life-time, but that can >> be done (mainly) by Unchecked_Deallocation, so it involves "unchecked" >> programming. Hm. >> > Is that because the heap allocated object is allocated using an > anonymous access type instead of a named access type per chance? > I know anonymous access types have different accessibility level > rules. It might be setting the accessibility level to the point > of call maybe? I made some more experiments: a) anonymous access (Aux.Init (new Aux.Rec)): check fails b) local named type "access Aux.Rec": check fails c) library-level access type (access Aux.Rec declared in package Aux): works. Interesting... I haven't developed a good intuition for this yet. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .