From: hreba <f_hreba@yahoo.com.br>
Subject: Re: How can one record component be local and another not?
Date: Wed, 6 May 2020 15:13:05 +0200
Date: 2020-05-06T15:13:05+02:00 [thread overview]
Message-ID: <hhfrf2F28pnU1@mid.individual.net> (raw)
In-Reply-To: <hhdvjsFkrklU1@mid.individual.net>
On 5/5/20 10:11 PM, Niklas Holsti wrote:
> On 2020-05-05 22:04, 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;
>>> --
>>>
>>> It compiles nicely, and then:
>>>
>>> frank@pc-frank:~/Temp/Test0$ ./test
>>> raised PROGRAM_ERROR : aux.adb:4 accessibility check failed
>>>
>>> #@!!0ßx*~@!!!
>>
>> Ok, apologies if I led you down the wrong path. I admit I did not
>> build a running program to check my suggestion of the "access"
>> parameter, and I have not myself often used this kind of code.
>>
>> You should be able to get rid of this error by using
>> r.a'Unchecked_Access instead of r.a'Access, and then (I think) you can
>> return to using an "in out" parameter mode instead of "access" mode.
>
> ... but better make it "aliased in out" to ensure pass-by-reference.
Perfect Niklas, all your proposed variants work!
> I do agree with Dmitry that records with internal pointers-to-component
> should be "limited" or "controlled".
Did that already, as you can see above.
It was a recurring issue for me but only now I understood it and know
how to solve it.
Thanks a lot for your help.
--
Frank Hrebabetzky, Kronach +49 / 9261 / 950 0565
next prev parent reply other threads:[~2020-05-06 13:13 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 [this message]
2020-05-06 17:30 ` Niklas Holsti
2020-05-06 18:28 ` Jere
2020-05-06 19:09 ` Niklas Holsti
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