comp.lang.ada
 help / color / mirror / Atom feed
* Re: Help: Type not accessible
@ 2002-03-19 14:45 Christoph Grein
  2002-03-19 19:02 ` Stephen Leake
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Grein @ 2002-03-19 14:45 UTC (permalink / raw)


> 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.


You've fallen victim to the accessibility level problem. Your Navpointer has a 
longer lifetime than your variable Mynav. You could copy Pointer_To_Nav to 
another pointer with longer lifetime than Main, i.e. it would point to an object 
that no longer exists.

That you don't do this here is irrelevant, what matters is lifetime or in RM 
speak accessibility levels.

Use 'Unchecked_Access instead, and you're on yourself to prevent dangling 
pointers.



^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: Help: Type not accessible
@ 2002-03-20  5:52 Christoph Grein
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Grein @ 2002-03-20  5:52 UTC (permalink / raw)


From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
> Christoph Grein <christoph.grein@eurocopter.com> writes:
> 
> > Use 'Unchecked_Access instead, and you're on yourself to prevent dangling 
> > pointers.
> 
> Please don't introduce hacks to newbies; show them the right way
> first! This is Ada, not C!
> 
> -- 
> -- Stephe

This is as little a hack as Unchecked_Deallocation. You simply need it in some 
cases... If 'Unchecked_Access is a hack, also 'Access is a hack. I rarely feel 
the need to use aliases.

Note that I gave complete information why 'Access does not work (omitted in your 
quote).



^ permalink raw reply	[flat|nested] 5+ messages in thread
* Help: Type not accessible
@ 2002-03-19 13:58 Mattimus
  2002-03-19 14:36 ` Stephen Leake
  0 siblings, 1 reply; 5+ 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] 5+ messages in thread

end of thread, other threads:[~2002-03-20  5:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-19 14:45 Help: Type not accessible Christoph Grein
2002-03-19 19:02 ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2002-03-20  5:52 Christoph Grein
2002-03-19 13:58 Mattimus
2002-03-19 14:36 ` Stephen Leake

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