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.6 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,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: aschwarz1309@att.net Newsgroups: comp.lang.ada Subject: Re: Ada Pointer Problem Date: Fri, 01 Oct 2004 19:34:13 +0000 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org X-Trace: melchior.cuivre.fr.eu.org 1096660302 8778 212.85.156.195 (1 Oct 2004 19:51:42 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Fri, 1 Oct 2004 19:51:42 +0000 (UTC) Cc: skidmarks , "comp.lang.ada@ada.eu.org" To: "David C. Hoos" Return-Path: X-Mailer: AT&T Message Center Version 1 (Jul 19 2004) X-Authenticated-Sender: YXNjaHdhcnoxMzA5QGF0dC5uZXQ= 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:4531 Date: 2004-10-01T19:34:13+00:00 Thanks. However, if the object is declared in a scoped environment it would seem that the only way that a pointer error could occur would be with explicit exporting of a value. Wouldn't checking this be a more reasonable approach than rejecting benign instances (for the next iteration of Ada)? EXAMPLE: (or am I missing the point?) with Pkg; package body David is Object_Ptr : Pkg.Ptr_Type; procedure P1( Ptr : out Pkg.Ptr_Type ) is P1_Object_Ptr : Pkg.Ptr_Type; procedure P1_P1( Ptr : out Pkg.Ptr_Type ) is P1_P1_Object_Ptr : Pkg.Ptr_Type; begin -- P1_P1 P1_P1_Object_Ptr := 'Access; -- no harm so far P1_Object_Ptr := P1_P1_Object_Ptr; -- error Object_Ptr := P1_P1_Object_Ptr; -- error Ptr := P1_P1_Object_Ptr; -- error end P1_P1; begin -- P1 P1_Object_Ptr := 'Access; -- no harm so far Object_Ptr := P1_P1_Object_ptr; -- error Ptr := P1_Object_Ptr; -- error end P1; end David; > 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 > > >