From: Ludovic Brenta <ludovic.brenta@insalien.org>
Subject: Re: Ada Pointer Problem
Date: Fri, 01 Oct 2004 19:24:04 +0200
Date: 2004-10-01T19:27:20+02:00 [thread overview]
Message-ID: <87hdpetkqz.fsf@insalien.org> (raw)
In-Reply-To: 35f054ea.0410010726.466caebc@posting.google.com
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.
next prev parent reply other threads:[~2004-10-01 17:24 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-01 15:26 Ada Pointer Problem skidmarks
2004-10-01 15:50 ` David C. Hoos
2004-10-01 18:15 ` Jeffrey Carter
2004-10-01 17:24 ` Ludovic Brenta [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-10-01 19:34 aschwarz1309
2004-10-02 0:47 ` Jeffrey Carter
2004-10-02 23:37 ` Randy Brukardt
2004-10-06 15:43 ` skidmarks
2004-10-06 18:19 ` Jeffrey Carter
2004-10-16 3:53 ` Benjamin Ketcham
2004-10-16 13:25 ` John B. Matthews
2004-10-18 18:09 ` Georg Bauhaus
2004-10-06 19:29 ` Georg Bauhaus
2004-10-07 18:45 ` skidmarks
2004-10-08 0:35 ` Jeffrey Carter
2004-10-08 12:02 ` Jean-Pierre Rosen
2004-10-08 16:58 ` Ludovic Brenta
2004-10-08 23:26 ` Björn Persson
2004-10-10 18:01 ` skidmarks
2004-10-08 14:03 ` Georg Bauhaus
2004-10-08 14:23 ` Dale Stanbrough
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox