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,fba93c19bb4e7dbd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-11 03:01:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Q: Endless loop by dispatching Date: Fri, 11 Jul 2003 12:01:51 +0200 Message-ID: References: NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: uni-berlin.de 1057917664 6622921 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:40186 Date: 2003-07-11T12:01:51+02:00 List-Id: On Fri, 11 Jul 2003 10:22:54 +0200, Michael Erdmann wrote: >i got a problem with the following code fragment below. The Idea is that >the procedure Serialize defines the strategy how to display object which >are derived from A.Object. Searialize simply dispatches into the class >by calling a procedure Write, which does the job for the class. [...] >In the following fragment i am defining a package B with an >derived objec B.Object as below. When an instance of B.Object >shall be serialized, the element of the super class (A.Object) >shall be serialzed as well. The code looks nice and compiles >but does not work, since the Serialize dispatches again with >Object.B even ther was a a case given A.Object( This ). [...] >Does any body know, what this loop causes?! I am not sure >if this is a bug or simply i missed the point. Serialize is class-wide and a view conversion does not change the tag..I.e. you have a re-dispatching case. Re-dispatching is a dangerous thing. [I would like it removed from Ada] So Serialize re-dispatches to B.Write which again calls Serialize. >From design point of view, one should never call class-wide routines from specific ones, this warranties that dispatch happens only once. I suppose that you want sort of procedure expansion instead of complete overriding, if so, then you should explicitly call parent's Write, similarly as one does it for Initialize/Finalize: package body B is ... procedure Write (This : in Object) is begin -- A.Serialize( A.Object( This ) ); A.Write (A.Object (This)); -- Write parent's things Put_Line( "Q =" & Natural'Image(This.Q)); end Write; BTW, why do not you use Ada.Streams? It is for things like this. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de