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: Tue, 5 May 2020 15:44:33 +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 FMOeCaoKTWmR7TRWdsyX3AOBskoK/KuHJN076siUGbiRtFGboU Cancel-Lock: sha1:GAVYIvekYqwF4r0K2pYBb2+sXfI= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 In-Reply-To: Content-Language: de-DE Xref: reader01.eternal-september.org comp.lang.ada:58588 Date: 2020-05-05T15:44:33+02:00 List-Id: On 5/5/20 1:48 PM, Niklas Holsti wrote: > On 2020-05-05 14:04, hreba wrote: >> I have reduced my problem to the following example: >> >> package Aux is >>     type Integer_P is access all Integer; >>     type Rec is record >>        a: aliased Integer; >>        p: Integer_P; >>     end record; >> >>     procedure Init (r: in out Rec); >> end Aux; >> >> package body Aux is >>     procedure Init (r: in out Rec) is >>     begin >>        r.p:= r.a'Access;  -- <-- error! >>     end Init; >> end Aux; >> >> Compiling results in "non-local pointer cannot point to local object" >> indicating the marked line above. >> >> How can one record component be local and another not? >> >> Intention is to have a library subprogram Init() for initialization. >> How would I implement that instead? >> >> (The reason for the above construction is the need to pass a pointer >> to a C library function.) >> > > The parameter "r" might be passed by copy, in which case the r.a'Access > would point to the local copy, and become a dangling pointer on return > (copy-out). Now I understand. > It works if you replace "r: in out" with "r : access", which ensures > pass by reference. Perfect, works indeed. Thanks a lot. I tried another thing too: Changed Init into a constructor function returning r in an extended return statement. Didn't work. So even an extended return statement seems to create a local copy first. -- Frank Hrebabetzky, Kronach +49 / 9261 / 950 0565