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,9c98277c71c4cdcc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-11 10:24:18 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.direct.ca!look.ca!wn1feed!wn4feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc54.POSTED!not-for-mail From: "Mark Lundquist" Newsgroups: comp.lang.ada References: <3C163FBE.9CB75916@rz.uni-karlsruhe.de> Subject: Re: Unconstrained arrays X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: NNTP-Posting-Host: cbsR7-61719-7y-72703@rwcrnsc54 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc54 1008095057 cbsR7-61719-7y-72703@rwcrnsc54 (Tue, 11 Dec 2001 18:24:17 GMT) NNTP-Posting-Date: Tue, 11 Dec 2001 18:24:17 GMT Organization: AT&T Broadband Date: Tue, 11 Dec 2001 18:24:17 GMT Xref: archiver1.google.com comp.lang.ada:17777 Date: 2001-12-11T18:24:17+00:00 List-Id: "Michael Unverzagt" wrote in message news:3C163FBE.9CB75916@rz.uni-karlsruhe.de... > Hi! > > We have to write a programm that uses an unconstrained array of > ustrings, where the size of the array should be determined by user > input... > > How does this work? Someone told me, I have to use subtypes but... > Does anyone know a simple example where I can learn how I can define the > size of an array at runtime by user input? Hi Mike, The first thing to understand is that in Ada, the bounds of an array need not be static (they are constant, but need not be static). So they can be determined by a variable, a non-static constant, or some other non-static expression like a function call, and the array will likely be allocated from the stack, not the heap, and in any case you don't need any pointers or explicit heap allocation. So, two ways to do it: Way 1: procedure Main_Program is . . Array_Size : Natural; . . begin . . -- Get input from the user . -- into the variable Array_Size . declare My_Array : array (1 .. Array_Size) of Foo; begin . . -- do your thing... Way 2: procedure Main_Program is . . function Array_Size return Natural is Size_From_User : Natural; begin . - get input from user . . return Size_From_User ; end Array_Size; My_Array (1 .. Array_Size) of Foo; begin . . . Have fun, -- Mark