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 X-Received: by 2002:a24:68c6:: with SMTP id v189-v6mr1991378itb.11.1536763299264; Wed, 12 Sep 2018 07:41:39 -0700 (PDT) X-Received: by 2002:aca:d417:: with SMTP id l23-v6mr97559oig.7.1536763299138; Wed, 12 Sep 2018 07:41:39 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.linkpendium.com!news.linkpendium.com!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!x81-v6no342121ita.0!news-out.google.com!c63-v6ni609ith.0!nntp.google.com!x81-v6no342118ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 12 Sep 2018 07:41:38 -0700 (PDT) In-Reply-To: <04d2775f-8a9a-4280-be82-82f7ca70044d@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=73.205.150.94; posting-account=Ru7E4QoAAAC_HiQ2D8LjZ7rh1mbTNcVn NNTP-Posting-Host: 73.205.150.94 References: <7a6b1ae7-f142-458d-ab01-c36c8ed30659@googlegroups.com> <04d2775f-8a9a-4280-be82-82f7ca70044d@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <6754951c-4134-434b-b813-cffceca90bb6@googlegroups.com> Subject: Re: Error: "non-local pointer cannot point to a local object" From: NiGHTS Injection-Date: Wed, 12 Sep 2018 14:41:39 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:54331 Date: 2018-09-12T07:41:38-07:00 List-Id: On Tuesday, September 11, 2018 at 9:49:44 PM UTC-4, Brad Moore wrote: > On Tuesday, September 11, 2018 at 4:21:00 PM UTC-6, NiGHTS wrote: > > As the subject line indicates, I am having a compile error which I am h= aving difficulty solving. > >=20 > > I have two distinct records, in this example called "Master_Record" and= "Working_Record". One contains an Integer, the other a "pointer" to that I= nteger. In this context, Working_Record depends on Master_Record. There can= be many Working_Record instances for a single Master_Record. The Copy func= tion is intended to enforce this rule by acting as an object factory, requi= ring an instance of Master_Record to create Working_Record. I know this isn= 't perfect, so any suggestions on a better strategy would be appreciated. > >=20 > > Ultimately the purpose of this is for Working_Record to be a copy-frien= dly record, where Master_Record is not intended to be used directly, except= as a place to anchor the variable scope. The resulting code will be writte= n as a library object containing two records just like I have here, as well= as a Copy function. The user of this library object is expected to create = an instance of Master_Record, then copy it to Working_Record.=20 > >=20 > > ---------------------------------------- > > type Master_Record is record > > =20 > > Root : aliased Integer; > > -- Here is where other general variables are kept > > =20 > > end record; > > =20 > > type Working_Record is record > > =20 > > Root_Pointer : access Integer; > > -- Here is where specific instance variables are kept > > =20 > > end record; > > =20 > > function Copy ( > > =20 > > Source : in out Master_Record > > =20 > > ) return Working_Record is > > begin > > =20 > > return (Root_Pointer =3D> Source.Root'Access); -- << Error here= >> > > =20 > > end Copy; > > =20 > > MR : Master_Record; > > WR : Working_Record :=3D Copy (MR); =20 > > ---------------------------------------- > >=20 > > Any ideas on how to achieve this goal? I'm sure its something simple. T= hanks in advance! >=20 > One solution would be to use access discriminants. >=20 >=20 > eg. > package P is > =20 > type Master_Record is record=20 > =20 > Root : aliased Integer;=20 > -- Here is where other general variables are kept=20 > =20 > end record;=20 > =20 > type Working_Record (Root : not null access Integer) is record=20 > null; > -- Here is where specific instance variables are kept=20 > end record;=20 > =20 > end P; >=20 > with P; use P; >=20 > procedure Main is > MR : aliased Master_Record; > WR1 : Working_Record (Root =3D> MR.Root'Access); > WR2 : Working_Record (Root =3D> MR.Root'Access); > begin =20 > WR1.Root.all :=3D 35; > WR2.Root.all :=3D 36; > end Main; >=20 > regards, >=20 > Brad I like this strategy as it enforces my dependency requirement. Thank you.