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-Thread: 103376,64ced24a7e89252e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Unchecked deallocation question References: <41A4AAFF.5060407@mailinator.com> In-Reply-To: <41A4AAFF.5060407@mailinator.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Wed, 24 Nov 2004 17:24:01 GMT NNTP-Posting-Host: 63.184.105.190 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1101317041 63.184.105.190 (Wed, 24 Nov 2004 09:24:01 PST) NNTP-Posting-Date: Wed, 24 Nov 2004 09:24:01 PST Xref: g2news1.google.com comp.lang.ada:6424 Date: 2004-11-24T17:24:01+00:00 List-Id: Alex R. Mosteo wrote: > type Root is tagged record ... > > type Root_Access is access Root; > > type Derived is new Root with ... > > type Derived_Access is access Derived; > > procedure Free is > new Ada.Unchecked_Deallocation (Root'Class, Root_Access); Root_Access designates Root, not Root'Class. > > declare > It : Derived_Access := new Derived; > begin > Free (Root_Access (It)); -- <-- THIS DEALLOCATION I'M ASKING > end; > > The purpose is to have a single deallocator in the root package and to > not have to instantiate a lot of deallocators for derived types. You'd be better off having type Root_Access is access Root'Class; procedure Free is new ... ... It : Root_Access := new Derived; ... Free (It); But you'd really be better off not using access types, or encapsulating and hiding their use if that's not possible. -- Jeff Carter "My name is Jim, but most people call me ... Jim." Blazing Saddles 39