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-17 07:22:55 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dennison@telepath.com (Ted Dennison) Newsgroups: comp.lang.ada Subject: Re: Beginer problem: variable array size Date: 17 Sep 2002 07:22:54 -0700 Organization: http://groups.google.com/ Message-ID: <4519e058.0209170622.498a17e7@posting.google.com> References: NNTP-Posting-Host: 65.115.221.98 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1032272575 29340 127.0.0.1 (17 Sep 2002 14:22:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 17 Sep 2002 14:22:55 GMT Xref: archiver1.google.com comp.lang.ada:29075 Date: 2002-09-17T14:22:55+00:00 List-Id: "Nacho" wrote in message news:... > 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. Why? Its very rare that someone actually needs to change the size of an array after it has been created. If you don't know the size of the array until point X, you can almost always wait to declare the array until point X. Good Ada code generally declares arrays of the exact size needed, often as constants. C doesn't let you do this as easily, so most folk don't do things that way in C. But don't let C's lack of capability hamstring your Ada code. Even if you have to work on the array to find its true length (a very rare occurance), there are ways to declare it properly on the stack without using any (explicit) dynamic allocation. One of our favorite tricks here in c.l.a. is using recursive routines that return unconstrained array types. For an example of this technique, go look at http://www.adapower.com/lang/recstring.html . This does exactly what you are trying to do with your example below, except it uses character arrays, and the step is 256 elements instead of 50. > ... 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