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,b30bd69fa8f63cb2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-19 21:56:42 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!wn12feed!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc53.POSTED!not-for-mail Message-ID: <3EF293CC.7030105@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: C bug of the day References: <1054751321.434656@master.nyc.kbcfp.com> <7gBHa.12174$KF1.273806@amstwist00> <7RQHa.3141$Uh2.339@nwrdny01.gnilink.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.62.164.137 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc53 1056084984 24.62.164.137 (Fri, 20 Jun 2003 04:56:24 GMT) NNTP-Posting-Date: Fri, 20 Jun 2003 04:56:24 GMT Organization: AT&T Broadband Date: Fri, 20 Jun 2003 04:56:24 GMT Xref: archiver1.google.com comp.lang.ada:39475 Date: 2003-06-20T04:56:24+00:00 List-Id: Hyman Rosen wrote: > Having to inherit from a special type to get finalization is > especially cumbersome in a language which does not have multiple > inheritance. That's probably true, which is why the ability to combine access discriminants with controlled type mix-ins in Ada is so useful. ;-) Unfortunately, that only works for limited objects. You can still add an access component to the mix-in part of an object to provide finalization behavoir for the parent, but it is a bit trickier: with Ada.Finalization.Controlled; with System.Address_to_Access_Conversion; generic type Parent is tagged private; with procedure Initialize (Object : in out Parent); with procedure Adjust (Object : in out Parent); with procedure Finalize (Object : in out Parent); package Controlled_Mixins is type Controlled_Part is new Ada.Finalization.Controlled with record Parent_Access: Addresses.Object_Pointer; end record; package Addresses is new System.Address_to_Access_Conversion(Parent); type Child is new Parent with record CP: Controlled_Part; end record; private procedure Initialize (Object : in out Controlled_Part); procedure Adjust (Object : in out Controlled_Part); procedure Finalize (Object : in out Controlled_Part); end Controlled_Mixins; The body for this package should be considered as impementation specific, and is not provided here. Also it should be obvious that instantiating this package when type Parent is derived from Ada.Finialization.Controlled is asking for trouble. I'd ask for a generic formal: type Foo is not new Bar; if I didn't think this was a very special case, and one that normally should be avoided. Incidently this definitely comes in the "Part 2" class of things you can do in Ada, but shouldn't. Instead it is much better to have the parts of the object that need finalization wrapped in one or more controlled mixins. That way the mixins are self consistant, and no component is reaching up to modify the containing object. But you can do it.