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 08:07:52 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!eusc.inter.net!news.eusc.inter.net!boavista.snafu.de!news From: Michael Erdmann Newsgroups: comp.lang.ada Subject: Re: Q: Endless loop by dispatching Date: Fri, 11 Jul 2003 17:07:52 +0200 Organization: [Posted via] Inter.net Germany GmbH Message-ID: <3F0ED2C8.6080409@snafu.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.eusc.inter.net 1057936072 11747 213.73.71.108 (11 Jul 2003 15:07:52 GMT) X-Complaints-To: abuse@eusc.inter.net To: "Dmitry A. Kazakov" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en In-Reply-To: Xref: archiver1.google.com comp.lang.ada:40196 Date: 2003-07-11T17:07:52+02:00 List-Id: Dmitry A. Kazakov wrote: >>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: > Unfortuantly this was not the complete code. The Serialize was itended to do a more complex job, which i have to replicate any where i want to serialize an object. The original serialize code looks some what like this: procedure Serialize( This : in Object'Class ) is ........ a := next(Attributes(This'Tag)) while a /= null loop Write( this.all, a.id ); a := next(....); end loop; end; The procedure write is a procedures which writes out a selected attribute of an object. The procedure Serialize the complete object. I would have been great when i could write something like this in ada: procedure Serialize( This : in Object'Class ) is Serialize( Super( This ) ); a := next(Attributes(This'Tag)) while a /= null loop Write( this.all, a.id ); a := next(....); end loop; end; I think something like this does not exist in Ada!? > 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. I fact i am using Ada.Stream, but as i have written above the code was simply a consended version. > > --- > Regards, > Dmitry Kazakov > www.dmitry-kazakov.de