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 X-Received: by 2002:a05:6214:a0f:: with SMTP id dw15mr2779646qvb.236.1588685839265; Tue, 05 May 2020 06:37:19 -0700 (PDT) X-Received: by 2002:a05:6830:2439:: with SMTP id k25mr2382024ots.76.1588685838813; Tue, 05 May 2020 06:37:18 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.unit0.net!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 5 May 2020 06:37:18 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <05692e22-d639-4595-9b27-02995ae60d20@googlegroups.com> Subject: Re: How can one record component be local and another not? From: Jere Injection-Date: Tue, 05 May 2020 13:37:19 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:58587 Date: 2020-05-05T06:37:18-07:00 List-Id: On Tuesday, May 5, 2020 at 8:59:21 AM UTC-4, hreba wrote: > On 5/5/20 1:33 PM, AdaMagica wrote: > > Am Dienstag, 5. Mai 2020 13:04:56 UTC+2 schrieb hreba: > >> 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; > > > > Imagine you define a local Rec: > > > > with Aux; > > procedure Proc is > > R: Aux.Rec; > > begin > > Aux.Init (R); > > end Proc; > > > > Now R has shorter lifetime than the access type Integer_P. Thus you might have somewhere an access object AO with longer lifetime than R and try to assign > > AO := R.P; > > > > Try Unrestricted_Access. > > > > Don't understand that. R.a and R.p have exactly the same lifetime, which > is the lifetime of R, haven't they? > You are thinking about it in a way that looks at object lifetimes only. Ada often compares the lifetime of the access "type" to the lifetime of the object (called accessibility levels in the RM). I'm not sure why the decision to do it that way was made (I assume easier implementation at the time). I do know that some younger languages have worked out some pretty useful schemes for tracking object lifetimes along with the access variables. Rust comes to mind and SPARK is also coming along in that area as well. Additionally there are some rules concerning anonymous access types that allow a runtime checking of object lifetimes (as opposed to static checking of Rust and soon SPARK), but anonymous access types have a host of issues all their own and I don't know them well enough to comment on how to do that reliably.