comp.lang.ada
 help / color / mirror / Atom feed
* Help: Type not accessible
@ 2002-03-19 13:58 Mattimus
  2002-03-19 14:36 ` Stephen Leake
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mattimus @ 2002-03-19 13:58 UTC (permalink / raw)


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;

with Navs;
use Navs;

with Navinterfaces;
use Navinterfaces;

with Displays;
use Displays;

with Ada.Text_Io;
use Ada.Text_Io;


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


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.

Thanks a lot guys.






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

* Re: Help: Type not accessible
  2002-03-19 13:58 Help: Type not accessible Mattimus
@ 2002-03-19 14:36 ` Stephen Leake
  2002-03-19 15:08 ` Mattimus
  2002-03-19 15:13 ` Vadim Godunko
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2002-03-19 14:36 UTC (permalink / raw)


"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



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

* Re: Type not accessible
  2002-03-19 13:58 Help: Type not accessible Mattimus
  2002-03-19 14:36 ` Stephen Leake
@ 2002-03-19 15:08 ` Mattimus
  2002-03-19 15:13 ` Vadim Godunko
  2 siblings, 0 replies; 4+ messages in thread
From: Mattimus @ 2002-03-19 15:08 UTC (permalink / raw)


Thanks for the help gentlemen.
I now can do my testing using unchecked acces but will keep the dangling
pointer in mind for future reference.

Thanks again.

Matt





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

* Re: Type not accessible
  2002-03-19 13:58 Help: Type not accessible Mattimus
  2002-03-19 14:36 ` Stephen Leake
  2002-03-19 15:08 ` Mattimus
@ 2002-03-19 15:13 ` Vadim Godunko
  2 siblings, 0 replies; 4+ messages in thread
From: Vadim Godunko @ 2002-03-19 15:13 UTC (permalink / raw)


>     --create a pointer to the nav to give to the nav interface
>     Pointer_To_Nav := Mynav'Access;  <--- THIS LINE WILL NOT COMPILE

     Pointer_To_Nav := Mynav'Unchecked_Access;
 
Becuase Mynav is local variable.





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

end of thread, other threads:[~2002-03-19 15:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-19 13:58 Help: Type not accessible Mattimus
2002-03-19 14:36 ` Stephen Leake
2002-03-19 15:08 ` Mattimus
2002-03-19 15:13 ` Vadim Godunko

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