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,95a195198c452b32 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!news.zanker.org!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Finalization of a record containing a task Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.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: <4213b899$0$20902$ba620e4c@news.skynet.be> Date: Fri, 18 Feb 2005 12:27:01 +0100 Message-ID: NNTP-Posting-Date: 18 Feb 2005 12:24:31 MET NNTP-Posting-Host: 8776dfa8.newsread2.arcor-online.net X-Trace: DXC=NoCeeoADANl0_l3b[L=KQcQ5U85hF6f;djW\KbG]kaMhea\9g\;7NmeRIg`OAeOCMj[6LHn;2LCVn7enW;^6ZC`d<=9bOTW=MNn X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8415 Date: 2005-02-18T12:24:31+01:00 List-Id: On 17 Feb 2005 19:13:36 -0500, Robert A Duff wrote: > "Dmitry A. Kazakov" writes: > >>... (Hypothetically, if there were >> class-wide destructors, one would be able to do that.) > > Sounds interesting. Can you give details of what you mean? The idea is to have user-defined initialization / finalization of class-wide objects. After all, T'Class is as type as T, why shouldn't it have ctors? Because presently tagged objects are view-convertible to their classes, that automatically implies, that even specific tagged objects have to be initialized / finalized as classes. So let us have: type A is new Ada.Finalization....; type B is new A with ...; Then, to initialize B, we have to: 1. initialize B (and A from there) 2. initialize B'Class -- presently empty 3. initialize A'Class -- presently empty To finalize B: 1. finalize A'Class -- presently empty 2. finalize B'Class -- presently empty 3. finalize B (and A from there) Because now we have something class-wide to dispatch from that could solve the problem of dispatching from constructors. One will just dispatch from: Class_Initialize (Object : in out A'Class); At this stage B (or whatsoever derived object) is fully constructed, so we can safely dispatch on Object. Same with task components (and hypothetically with task ancestors): Class_Finalize could call Die_At_Once entry of its task component. >>... So in most cases one >> is forced to use access-to-task components rather than plain task ones. > > Yes, but if you declare the object in a library package, you'll > still have the same problem with finalization happening too late. Yes. ---------------------------- Should Ada some day have classes for non-tagged objects, then class-wide constructors / destructors would be called each time T is converted to T'Class and back. That would be a real conversion then, which at least adds / removes the type tag. It could become very interesting for by-reference parameter passing, though. For example: type A is ...; procedure Foo (Object : A); -- A is by-reference here type B is new A ...; X : constant A'Class := Some_B; begin Foo (X); upon dispatch to A.Foo, X has to be converted to plain A. For this it is first demoted from class by finalizing A'Class and then B'Class. Now Foo is ready to call. After Foo's completion, and even if an exception is propagated, X need to be heighten back to B'Class and A'Class. No matter, if it is a constant! (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de