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:a02:4ddc:: with SMTP id t89-v6mr24132807jad.19.1536716982805; Tue, 11 Sep 2018 18:49:42 -0700 (PDT) X-Received: by 2002:aca:5557:: with SMTP id j84-v6mr20032oib.3.1536716982638; Tue, 11 Sep 2018 18:49:42 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!x81-v6no100058ita.0!news-out.google.com!c63-v6ni13ith.0!nntp.google.com!x81-v6no100055ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 11 Sep 2018 18:49:42 -0700 (PDT) In-Reply-To: <7a6b1ae7-f142-458d-ab01-c36c8ed30659@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.66.161.135; posting-account=lzqe5AoAAADHhp_gregSufVhvwu22fBS NNTP-Posting-Host: 50.66.161.135 References: <7a6b1ae7-f142-458d-ab01-c36c8ed30659@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <04d2775f-8a9a-4280-be82-82f7ca70044d@googlegroups.com> Subject: Re: Error: "non-local pointer cannot point to a local object" From: Brad Moore Injection-Date: Wed, 12 Sep 2018 01:49:42 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:54328 Date: 2018-09-11T18:49:42-07:00 List-Id: 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 hav= ing 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 Int= eger. In this context, Working_Record depends on Master_Record. There can b= e many Working_Record instances for a single Master_Record. The Copy functi= on is intended to enforce this rule by acting as an object factory, requiri= ng 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-friendl= y record, where Master_Record is not intended to be used directly, except a= s a place to anchor the variable scope. The resulting code will be written = as a library object containing two records just like I have here, as well a= s 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. Tha= nks in advance! One solution would be to use access discriminants. 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; with P; use P; 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; regards, Brad