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=ham 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!news1.google.com!news.glorb.com!newsgate.cistron.nl!transit.news.xs4all.nl!195.241.76.212.MISMATCH!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Ada Pointer Problem References: <35f054ea.0410010726.466caebc@posting.google.com> From: Ludovic Brenta Date: Fri, 01 Oct 2004 19:24:04 +0200 Message-ID: <87hdpetkqz.fsf@insalien.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:2XG2hcXMvZlqHZjHOzhDL9x61RA= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 01 Oct 2004 19:27:20 CEST NNTP-Posting-Host: 83.134.243.150 X-Trace: 1096651640 dreader2.news.tiscali.nl 44070 83.134.243.150:37373 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:4520 Date: 2004-10-01T19:27:20+02:00 List-Id: skidmarks writes: > 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? Others have explained the problem, but I think you can solve it by declaring a local access type (not subtype): with A; procedure B is type Y is access all A.X; -- local to B Object : aliased a.X; -- also local to B Ptr : Y := Object'Access; begin -- B null; end B; I haven't tried or verified it in the RM, this is just a hint. But I think this solution reflects good design; it guarantees that Object exists for at least as long as type Y. Thus, you cannot pass Ptr to subprograms outside of B. -- Ludovic Brenta.