comp.lang.ada
 help / color / mirror / Atom feed
* Re: Ada Pointer Problem
@ 2004-10-01 19:34 aschwarz1309
  2004-10-02  0:47 ` Jeffrey Carter
  0 siblings, 1 reply; 21+ messages in thread
From: aschwarz1309 @ 2004-10-01 19:34 UTC (permalink / raw)
  To: David C. Hoos; +Cc: skidmarks, comp.lang.ada@ada.eu.org

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  := <local something>'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  := <local something>'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" <aschwarz@acm.org>
> Newsgroups: comp.lang.ada
> To: <comp.lang.ada@ada-france.org>
> 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
> >
> 



^ permalink raw reply	[flat|nested] 21+ messages in thread
* Ada Pointer Problem
@ 2004-10-01 15:26 skidmarks
  2004-10-01 15:50 ` David C. Hoos
  2004-10-01 17:24 ` Ludovic Brenta
  0 siblings, 2 replies; 21+ messages in thread
From: skidmarks @ 2004-10-01 15:26 UTC (permalink / raw)


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;



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2004-10-18 18:09 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-01 19:34 Ada Pointer Problem 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
  -- strict thread matches above, loose matches on Subject: below --
2004-10-01 15:26 skidmarks
2004-10-01 15:50 ` David C. Hoos
2004-10-01 18:15   ` Jeffrey Carter
2004-10-01 17:24 ` Ludovic Brenta

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