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!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Aliased References: <1118851601.345326.86640@g49g2000cwa.googlegroups.com> <1118991665.365498.233060@z14g2000cwz.googlegroups.com> <1119210250.852024.100660@g49g2000cwa.googlegroups.com> <1119260078.916073.75200@g47g2000cwa.googlegroups.com> In-Reply-To: <1119260078.916073.75200@g47g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Mon, 20 Jun 2005 16:41:56 GMT NNTP-Posting-Host: 67.3.180.237 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1119285716 67.3.180.237 (Mon, 20 Jun 2005 09:41:56 PDT) NNTP-Posting-Date: Mon, 20 Jun 2005 09:41:56 PDT Xref: g2news1.google.com comp.lang.ada:11502 Date: 2005-06-20T16:41:56+00:00 List-Id: nblanpain@hotmail.com wrote: > But in this case, i can't implement the procedure Initialize : > "This.Ptr_Array := new T_Array (1.. Dynamic_Size);" is illegal > (Ptr_array is constrained). If T_Array is constrained, or Ptr_Array designates a constrained subtype of T_Array, then this would be illegal. It would help if you quoted some context in your replies. It would also help if we knew what you were trying to accomplish, not just how you were trying to do it. This looks as if you want a variable-size array, but you're asking about access types and aliased components. Variable arrays in Ada are usually implemented using an unconstrained variable, a variant record with a default discriminant: Max_Size : constant := 100; -- or whatever -- It's a good idea to specify a max to avoid Storage_Error, -- since most compilers will allocate enough storage for the -- maximum possible size. subtype Index is Positive range 1 .. Max_Size; type Fixed is array (Index range <>) of ...; type Variable_Array (Size : Index := Max_Size) is record Value : Fixed (1 .. Size); end record; R : Variable_Array; R := Variable_Array'(Size => 32, Value => Fixed'(1 .. 32 => ...) ); This provides a bounded array, which can vary between 1 and Max_Size elements. An alternative is an unbounded array, usually implemented using access and controlled types: type Fixed is array (Positive range <>) of ...; type Unbounded_Array is private; function To_Unbounded (Item : Fixed) return Unbounded_Array; function To_Fixed (Item : Unbounded_Array) return Fixed; This would be implemented as type Fixed_Ptr is access Fixed; type Unbounded_Array is new Ada.Finalization.Controlled with record Ptr : Fixed_Ptr; end record; procedure Adjust (Object : in out Unbounded_Array); procedure Finalize (Object : in out Unbounded_Array); Of course you hide the use of access types from your client to avoid dangling references. Adjust handles deallocation on assignment, and Finalize on finalization. If you really need an unbounded array abstraction, though, you should look at the Vector container that will be part of the Ada 0X revision (X will probably equal 6). An Ada-95 version is available somewhere; check adapower.com or adaworld.com. -- Jeff Carter "Blessed is just about anyone with a vested interest in the status quo." Monty Python's Life of Brian 73