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,e91f674b5db5e2b2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-16 02:32:13 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed1.uncensored-news.com!propagator-la!news-in-la.newsfeeds.com!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.sfba.home.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Access types and classwide programming References: <09Oo7.12082$mj6.1852826@news6-win.server.ntlworld.com> X-Newsreader: Tom's custom newsreader Message-ID: Date: Sun, 16 Sep 2001 09:32:13 GMT NNTP-Posting-Host: 24.7.82.199 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.sfba.home.com 1000632733 24.7.82.199 (Sun, 16 Sep 2001 02:32:13 PDT) NNTP-Posting-Date: Sun, 16 Sep 2001 02:32:13 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:13102 Date: 2001-09-16T09:32:13+00:00 List-Id: > procedure test_x is > > temp : aliased xxx; > > begin > init (temp); -- this is ok! > > put( get_something(temp'access)); -- error 1 here > end x; > > error 1 is "non-local pointer cannot point to local object" Suppose function get_something put a copy of its parameter into a global variable. After exiting text_x, that global would be a pointer to ??? Thus the error message. There are two solutions: define get_something to take as parameter a type which is declared inside of text_x, in which case clearly no global could exist for get_something to set, or else else temp'unchecked_access, thus telling the compiler "I know this is dangerous but I've looked carefully and it's OK here". > What I want to do is to have a variable of type xxx and to pass it to > get_something and to init. The "init" case already works fine. Why not change get_something to function get_something (sc : in xxx'class) return integer; thus getting rid of the access type and the problem. Suppose you have a tagged type ttype, and need an access type to ttype and it's class. > type ttype is tagged ...; > type ttype_access is access all ttype; > typ ttype_caccess is access all ttype'class; -- [surely you meant this] > > How do you > > a) get "access" to a variable of ttype? x : aliased ttype; p : ttype_access; ... p := x'access; p := new ttype; > b) create a new instance of a ttype which is pointed to by a variable of > type ttype_caccess? y : aliased ttype; p : ttype_caccess; ... p := x'access; p := new ttype;