comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: How can one record component be local and another not?
Date: Wed, 6 May 2020 22:09:40 +0300
Date: 2020-05-06T22:09:40+03:00	[thread overview]
Message-ID: <hhggblF6munU1@mid.individual.net> (raw)
In-Reply-To: <1e054635-6c0a-41ca-8cc2-080aa5f532a3@googlegroups.com>

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;
>>> -- 
>>>
>> <SNIPPED>
>> 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
       .      @       .

  reply	other threads:[~2020-05-06 19:09 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-05 11:04 How can one record component be local and another not? hreba
2020-05-05 11:33 ` AdaMagica
2020-05-05 11:38   ` AdaMagica
2020-05-05 12:59   ` hreba
2020-05-05 13:19     ` J-P. Rosen
2020-05-05 13:37     ` Jere
2020-05-05 14:28       ` hreba
2020-05-05 15:18         ` AdaMagica
2020-05-05 14:32   ` hreba
2020-05-05 11:43 ` AdaMagica
2020-05-05 12:55   ` hreba
2020-05-05 11:46 ` Simon Wright
2020-05-05 13:07   ` hreba
2020-05-05 17:00     ` Dmitry A. Kazakov
2020-05-05 11:48 ` Niklas Holsti
2020-05-05 13:44   ` hreba
2020-05-05 15:45 ` Jeffrey R. Carter
2020-05-05 17:17   ` hreba
2020-05-05 19:08     ` Niklas Holsti
2020-05-06 19:31       ` hreba
2020-05-09 19:43         ` Niklas Holsti
2020-05-10 15:10           ` hreba
2020-05-05 19:19     ` Jere
2020-05-06  6:42     ` Mark Lorenzen
2020-05-06  8:26       ` Simon Wright
2020-05-06  8:33         ` Mark Lorenzen
2020-05-05 17:32 ` hreba
2020-05-05 19:04   ` Niklas Holsti
2020-05-05 20:11     ` Niklas Holsti
2020-05-06 13:13       ` hreba
2020-05-06 17:30   ` Niklas Holsti
2020-05-06 18:28     ` Jere
2020-05-06 19:09       ` Niklas Holsti [this message]
2020-05-07  9:07     ` J-P. Rosen
2020-05-07 10:15       ` Niklas Holsti
2020-05-07 13:00         ` Egil H H
2020-05-07 13:25         ` Simon Wright
2020-05-07 10:31       ` Stefan.Lucks
2020-05-07 11:58         ` J-P. Rosen
replies disabled

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