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: Tue, 5 May 2020 14:48:27 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net 10Hpvm1spwwfDDzYQqFydQnCZp2OWuwOQ54STvFmTmoAIf0FaI Cancel-Lock: sha1:051MJ229DvpokYLPXhLG1s6cwMY= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:58582 Date: 2020-05-05T14:48:27+03:00 List-Id: 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). It works if you replace "r: in out" with "r : access", which ensures pass by reference. It did not work for me (same error message) if I just added "aliased", making "r : aliased in out Rec", although I think that should also be enough to ensure pass by reference. This was on GNAT Community 2019 (20190517-83), Mac. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .