comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
To: "comp.lang.ada mail to news gateway" <comp.lang.ada@ada.eu.org>
Subject: Re: Newbie question about pointers in GNAT 3.15p on Windows 2000
Date: Fri, 21 Feb 2003 17:03:14 -0600
Date: 2003-02-21T17:03:14-06:00	[thread overview]
Message-ID: <mailman.35.1045868531.9948.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: 816517EFDE1ABFFF.672EFD9C99861B55.1999743ACE4BA64B@lp.airnews.net

"Local" refers to the declarative region of the function X.

That the pointer is "non-local" is a consequence of the fact that
the pointer _type_ is not in the local region.

It's hard to see what is the point of this exercise, since the
value of P_Size is not used.  But, in general taking the access of
a variable on the stack is not very useful (e.g., to return it as
the result of a function), since the local stack variable is subject
to corruption upon return from the function.


----- Original Message ----- 
From: "David Gressett" <gressett@airmail.net>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: February 21, 2003 3:20 PM
Subject: Newbie question about pointers in GNAT 3.15p on Windows 2000


> 
> I have the following package which I am trying to compile with GNAT
> 3.15p on Windows 2000:
> 
> -----------------------------------------------------------------------
> package Miscellaneous3 is
> 
>   
>   function X
>     return String;
>     
> end Miscellaneous3;
> 
> 
> package body Miscellaneous3 is
> 
>   -----------------------
>   -- X --
>   -----------------------
>   
>   type P_Integer is access all Integer;
> 
>   function X
>     return String
>   is
>     Bufsize: Aliased Integer;
>     P_Size: P_Integer;
>     
>   begin
>     Bufsize := 1;
>     P_Size := BufSize'Access;
>     return "";
>   end X;
> 
> end Miscellaneous3;
> 
> ---------------------------------------------------------------------
> Compilation produces this error message:
> 
> miscellaneous3.adb:17:15 non-local pointer cannot point to local
> object
> 
> I have no idea what "local" means here -  both the pointer P_Size and
> the pointed-to variable Bufsize are defined in the same place.
> 
> What am I doing wrong?
> 
> 
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 




  reply	other threads:[~2003-02-21 23:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-21 21:20 Newbie question about pointers in GNAT 3.15p on Windows 2000 David Gressett
2003-02-21 23:03 ` David C. Hoos, Sr. [this message]
2003-02-24 19:05   ` David Gressett
2003-02-24 19:25     ` David Gressett
2003-02-22 15:31 ` Steve
2003-02-24  6:40   ` Newbie question about pointers in GNAT 3.15p on Windows 2000 : to Steve prashna
2003-02-25  2:57     ` Steve
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox