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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,efe381d5ed2da234 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada Subject: Re: Ada Pointer Problem Date: Fri, 1 Oct 2004 10:50:18 -0500 Organization: Cuivre, Argent, Or Message-ID: References: <35f054ea.0410010726.466caebc@posting.google.com> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1096645837 61505 212.85.156.195 (1 Oct 2004 15:50:37 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Fri, 1 Oct 2004 15:50:37 +0000 (UTC) Cc: "comp.lang.ada@ada.eu.org" To: "skidmarks" Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:4512 Date: 2004-10-01T10:50:18-05:00 The problem is that Object is local to procedure B, while X_Ptr is declared at library level (i.e., non-local). The principle is that Object exists only when procedure B is executing, and what is trying to be prevented is having a value of type X_Ptr available when Object no longer exists. This could happen if B were not the main procedure, but were instead a library-level procedure that could be called by some other subprogram. Since procedure B is known to the programmer to be the main procedure, in this case, if one is using GNAT, one could use the 'Unrestricted_Access attribute, instead of the 'Access attribute, and do what you want. ----- Original Message ----- From: "skidmarks" Newsgroups: comp.lang.ada To: Sent: Friday, October 01, 2004 10:26 AM Subject: Ada Pointer Problem > Each Ptr assignment below yields the following error message: > > -- 9. Ptr : a.X_Ptr := Object'Access; > -- non-local pointer cannot point to local object > > In the past, the only way that I seem to be able to fix the problem is to > put the pointer and assignment in global space (either in file global or > in a package spec). I've looked at Ada as a Second Language (Cohen) and, > with less diligence, at the Ada LRM but can't figure what I'm doing wrong. > What am I doing wrong? > > thanks > art > > ----------------------------------------------------------- > ----------------------------------------------------------- > > package a is > type X is new Integer; > type X_Ptr is access all X; > end a; > > -------------------------------------------------------- > > -- Main Program > > with a; > > Procedure b is > subtype Y is a.X; > subtype Y_Ptr is a.X_Ptr; > > Object : aliased a.X; > Object_Y: aliased Y; > Ptr : a.X_Ptr := Object'Access; > Ptr_Y : Y_Ptr := Object'Access; > Ptr_OY : a.X_Ptr := Object'Access; > Ptr_1Y : Y_Ptr := Object'Access; > > begin -- b > Ptr := Object'Access; > Ptr_Y := Object'Access; > end b; > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada-france.org > http://www.ada-france.org/mailman/listinfo/comp.lang.ada >