comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Help: Type not accessible
Date: 19 Mar 2002 09:36:59 -0500
Date: 2002-03-19T14:42:31+00:00	[thread overview]
Message-ID: <ur8mg62us.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: muHl8.37472$X2.358367@nnrp1.uunet.ca

"Mattimus" <mattisgrat@yahoo.ca> writes:

> Ok guys here's the jist of what I have.
> 
> package Navs is
> 
>     type Nav is tagged
>         record
>             Position : Integer;
>         end record;
> 
>     type Navpointer is access all Nav;
> 
>     function Getposition (Anav : in Nav) return Integer;
>     procedure Setposition (Anav : in out Nav; Anint : in Integer);
> end Navs;

This package declares an access type at "library level". This means
that there _can_ be variables of type Navpointer that _never_ go out
of scope.

><snip>
> 
> procedure Main is
> 
>     Mynav : aliased Nav;
> 
>     Pointer_To_Nav : Navpointer;
> 
>  begin
> 
>     --create a pointer to the nav to give to the nav interface
>     Pointer_To_Nav := Mynav'Access;  <--- THIS LINE WILL NOT COMPILE
> 

Mynav is in a procedure, which is a lower level than "library"; it
_can_ go out of scope. Sure, in this case it's the "main" procedure,
but the compiler doesn't know that (remember, the name "main" is _not_
special in Ada). So the compiler says "saving a pointer to Mynav is
bad, since it may go out of scope, and then you'd have a dangling
pointer". 

> It tells me that 'Mynav is not accessible from access all nav'. Can
> someone please help. I have no idea what to do here, or what is
> causing it.

The solution is to declare another package, say Main_Package, and
declare the pointer there. Packages are at library level, they don't
go out of scope.

In general, you will find that you need to declare most of your
application at library level, and very little in the actual main
routine. 

-- 
-- Stephe



  reply	other threads:[~2002-03-19 14:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-19 13:58 Help: Type not accessible Mattimus
2002-03-19 14:36 ` Stephen Leake [this message]
2002-03-19 15:08 ` Mattimus
2002-03-19 15:13 ` Vadim Godunko
  -- strict thread matches above, loose matches on Subject: below --
2002-03-19 14:45 Help: " Christoph Grein
2002-03-19 19:02 ` Stephen Leake
2002-03-20  5:52 Christoph Grein
replies disabled

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