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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: hreba Newsgroups: comp.lang.ada Subject: Re: How can one record component be local and another not? Date: Wed, 6 May 2020 15:13:05 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net FPsf8YA02AsbiGSj8Pq6ewd3YMsKAxZtMBb35lEZ1jvmI/BUk3 Cancel-Lock: sha1:wsBTXWKAQTZ7nJ2Sx8O4tKwlA5g= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:58613 Date: 2020-05-06T15:13:05+02:00 List-Id: 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