comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: How can one record component be local and another not?
Date: Tue, 5 May 2020 06:37:18 -0700 (PDT)
Date: 2020-05-05T06:37:18-07:00	[thread overview]
Message-ID: <05692e22-d639-4595-9b27-02995ae60d20@googlegroups.com> (raw)
In-Reply-To: <hhd697FfhvdU1@mid.individual.net>

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.

  parent reply	other threads:[~2020-05-05 13:37 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 [this message]
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
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