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,436e4ce138981b82 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-12 12:05:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!news-FFM2.ecrc.net!eusc.inter.net!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: abstract sub programs overriding Date: Fri, 12 Mar 2004 20:05:32 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <1078849973.701176@master.nyc.kbcfp.com> <67u0505uu3gfmlt8p28e9jkaco0nljquut@4ax.com> <1079019616.621636@master.nyc.kbcfp.com> <1079026002.840030@master.nyc.kbcfp.com> <1079097006.572713@master.nyc.kbcfp.com> <1079103394.507060@master.nyc.kbcfp.com> <1079116458.119831@master.nyc.kbcfp.com> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1079121932 25393 134.91.1.34 (12 Mar 2004 20:05:32 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Fri, 12 Mar 2004 20:05:32 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: archiver1.google.com comp.lang.ada:6288 Date: 2004-03-12T20:05:32+00:00 List-Id: Hyman Rosen wrote: : : But it also means that initializing a field of B cannot safely use A! So it seems. Here is an example producing Init field of B hook has val -1073743060 Init B when the main subprogram has a declaration of a variable of type B but not of type A. When a variable of type A is added before the B variable, the B variables initial hook val becomes 0. If an A variable is declared after a B variable, the Natural hook val stays at -1073743060. (GCC 3.1 Mac OS X) with Ada.Finalization; use Ada.Finalization; package Foo is type Hook is tagged record -- not part of hierarchy val: Natural; -- should not have negative values end record; procedure hook_op(ref: access Hook); type A is new Controlled with record a_part: aliased Hook; end record; procedure Initialize(Object: in out A); type In_B is new Controlled with null record; procedure Initialize(object: in out In_B); type B is new A with record field: In_B; end record; procedure Initialize(Object: in out B); end foo; with Ada.Text_IO; use Ada.Text_IO; package body Foo is procedure hook_op(ref: access Hook) is begin put_line("hook has val " & Natural'image(ref.val)); end hook_op; procedure Initialize (Object : in out A) is begin Put_Line ("Init A"); end Initialize ; procedure Initialize (Object : in out B) is begin hook_op(Object.a_part'access); Put_Line ("Init B"); end Initialize ; procedure Initialize (Object : in out In_B) is begin Put_Line ("Init field of B"); end Initialize; end Foo;