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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e008f8da6c083c62 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed.freenet.de!news.albasani.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Anonymous access types Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1181294988.270499.202550@g4g2000hsf.googlegroups.com> Date: Fri, 8 Jun 2007 14:01:09 +0200 Message-ID: <8oh0idncjgii$.1tm1fzqvqv3cb$.dlg@40tude.net> NNTP-Posting-Date: 08 Jun 2007 13:58:38 CEST NNTP-Posting-Host: 737df78f.newsspool2.arcor-online.net X-Trace: DXC=CdLj9k3:1jP\PS5Xo=M[RVA9EHlD;3YcR4Fo<]lROoRQ8kF_BUjBegBXUD_ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:16104 Date: 2007-06-08T13:58:38+02:00 List-Id: On Fri, 08 Jun 2007 02:29:48 -0700, adam.betts155@gmail.com wrote: > I am having some trouble with anonymous access types, behaviour which > I do not understand. I have 2 questions: > > 1) This one is bizarre and quite non-deterministic. I *sometimes* get > a "finalize/adjust raised exception" with the following bit of code: > > declare > t_ptr : tree_pointer := new tree'(get_tree(g)); > anon_t_ptr : access tree'class := new tree'(get_tree(g)); > lca : least_common_ancestor(anon_t_ptr); > begin > end; This leaks, where these objects get deallocated? > with the following type declarations: > tree_pointer is access tree'class; > type least_common_ancestor (tree_ptr: access constant tree'class); > > It seems that there is sometimes a problem with the lca declaration, > since the exception is never raised when anon_t_ptr is replaced with > t_ptr. I guess it is because of accessibility checks. t_ptr and anon_t_ptr have different accessibility levels. When you call to least_common_ancestor, which probably has its parameter of some access type declared in an enclosing scope, then anon_t_ptr being converted fails on accessibility check. In the result you get a snowball of misleading secondary faults. (never use pointers if you can) > 2) I want to return an anonymous access type from a function: > > function get_tree (g: graph) return non null access tree is > begin > return new tree(g.t); > end get_tree; > > The access type is not null when I use this function. However, when I > run the code and try to do operations on the access type, it is not > pointing in the right place. For example, the returned tree does not > have vertices and edges even though I know it does. new tree(g.t); does not initialize the object beyond standard initialization. You probably meant new tree'(); -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de