From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,23211966662bb231 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-19 06:45:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Help: Type not accessible Date: 19 Mar 2002 09:36:59 -0500 Organization: NASA Goddard Space Flight Center Message-ID: References: NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1016548951 9259 128.183.220.71 (19 Mar 2002 14:42:31 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 19 Mar 2002 14:42:31 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Xref: archiver1.google.com comp.lang.ada:21452 Date: 2002-03-19T14:42:31+00:00 List-Id: "Mattimus" 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. > > > 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