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-Thread: 103376,98e3ee7e73b9dd89 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!newscon02.news.prodigy.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Aliased Date: 29 Jun 2005 17:10:15 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1118851601.345326.86640@g49g2000cwa.googlegroups.com> <1118930589.514028.150340@g47g2000cwa.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1120079415 9254 192.74.137.71 (29 Jun 2005 21:10:15 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 29 Jun 2005 21:10:15 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:11741 Date: 2005-06-29T17:10:15-04:00 List-Id: nblanpain@hotmail.com writes: > So this is my sources and the compilation error : > > ------ Container.ads > generic > type T_Item is private; > Static_Size : Integer; > package Container is > type T_Array is array (Integer range <>) of T_Item; > type A_Array is access all T_Array; > type T_Container is tagged record > Obj_Array : aliased T_Array (1..Static_Size); > Ptr_Array : A_Array; > end record; > procedure Initialize (This : in out T_Container; Dynamic_Size : in > Integer); > function P_Array (This : in T_Container) return A_Array; > end Container; I have a package that tries to do something similar. Try wrapping the array in a record: type T_Rec(Length: Natural) is record A: T_Array(1..Length); end record; type T_Rec_Ptr is access all T_Rec; type T_Container is tagged record Obj_Array : aliased T_Rec (Length => Static_Size); Ptr_Array : T_Rec_Ptr; end record; Then Initialize can set Ptr_Array to either "new T_Rec(Length => Dynamic_Size)" or "This.Obj_Array'Access". Well, you'll want to change the names of things to make sense... > ------ Container.adb > package body Container is > procedure Initialize (This : in out T_Container; Dynamic_Size : in > Integer) is > begin > if Dynamic_Size /= 0 then > This.Ptr_Array := new T_Array (1.. Dynamic_Size); > elsif Static_Size /= 0 then > This.Ptr_Array := This.Obj_Array'Access; --- Compilation Error > end if; > end Initialize; > function P_Array (This : in T_Container) return A_Array is > begin > return This.Ptr_Array; > end P_Array; > end Container; > > -- Compilation Error : Object subtype must statically match designated > subtype. No local pointer cannot point to local object. - Bob