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,bb05655456eafe6d,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.251.MISMATCH!transit4.readnews.com!textspool1.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Thu, 13 Dec 2007 07:20:46 -0500 From: "Peter C. Chapin" User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Q about finalization and interfaces. Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4761239f$0$31576$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: f0f98df4.news.sover.net X-Trace: DXC=6FH;G9`:FV5:XR= I'm trying to understand the interaction between controlled types, interfaces, and class-wide dispatching. Accordingly I wrote the following program, which I will present in sections. First the package specification: with Ada.Finalization; package Check_Package is type B is interface; procedure Do_Stuff( Thing : in B ) is abstract; type D is new Ada.Finalization.Controlled and B with record X : Integer := 0; end record; overriding procedure Do_Stuff( Thing : in D ); overriding procedure Finalize( Thing : in out D ); end Check_Package; The idea is that I want to build a derivation class rooted on the B interface with some of the types in that class (such as D) being controlled. The corresponding body prints out a few messages to help track what is happening. Note that I use the X component as a kind of object ID number. with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; package body Check_Package is procedure Do_Stuff( Thing : in D ) is begin Put("Do_Stuff( Thing : in D ) => "); Put(Thing.X); New_Line; end Do_Stuff; procedure Finalize( Thing : in out D ) is begin Put("Finalize( Thing : in out D ) => "); Put(Thing.X); New_Line; end Finalize; end Check_Package; Now the test program that exercises the above code looks like this: with Check_Package; use Check_Package; procedure Check is Object : D; Some_Thing : B'Class := Object; begin Object.X := -1; Do_Stuff(Some_Thing); end Check; Using GNAT GPL 2007 I get the following output: Finalize( Thing : in out D ) => 0 Finalize( Thing : in out D ) => -1 My interpretation is that Object is copied (with the default ID value of zero) when Some_Thing is initialized; Object's ID is then modified. Both Object and its copy are finalized when the program ends. But... what happened to my call to Do_Stuff?? I expected that call to dispatch on Some_Thing and invoke the Do_Stuff for type D. What am I misunderstanding? Thanks in advance! Peter