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,71c743c03ed191fe X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-15 10:45:59 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!news.stealth.net!news.stealth.net!central.cox.net!cox.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3D84C762.9030705@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Beginer problem: variable array size References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 15 Sep 2002 17:46:00 GMT NNTP-Posting-Host: 63.184.1.132 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1032111960 63.184.1.132 (Sun, 15 Sep 2002 10:46:00 PDT) NNTP-Posting-Date: Sun, 15 Sep 2002 10:46:00 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:28987 Date: 2002-09-15T17:46:00+00:00 List-Id: Nacho wrote: > That does not resolve the problem. I need to change the size of the array > after it has been created. With your solution once array_called_p has been > created it will never change its size. > > I need this: > > ... preceding Ada statements > declare -- scope of array_called_p > type my_array_type is array ( positive range <> ) of integer; > array_called_p : my_array_type ( 1 .. variable ); > begin -- scope of array_called_p > ... Ada statements that use array_called_p > > variable := variable+50; -- We increase the size of the array in 50 > elementes > .... HERE I need array_called_p to increase its size so it can hold > 50 more elements > > end; -- scope of array_called_p > ... following Ada statements It may solve your problem. Consider Multiple_Arrays : loop ... Size := Some_Function; -- Some_Function may be a random number generator, -- obtain the value interactively from the user, or -- so on ... Scope_Of_P : declare P : Some_Array_Type (1 .. Size); begin -- Scope_Of_P ... end Scope_Of_P; ... end loop Multiple_Arrays; Here you deal repeatedly with an array named P, with a different size each time. And, look Ma!, no pointers. Of course, if you design your program with the assumption that P has to be implemented using pointers, then this approach may not fit into your design. But that is a problem with your design, not with this approach. Certainly it is possible to use arrays as in C, but it is rarely necessary. In your C++ example, you do not have one array with 2 different sizes, you have two arrays, accessed misleadingly through the same pointer. The 2nd array has nothing to do with the first, which no longer exists, having been freed. In Ada, this would involve a second block statement declaring a second array. Still no pointers? Sorry. -- Jeff Carter "Son of a window-dresser." Monty Python & the Holy Grail