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,bd942c6fce519d49,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-21 10:32:22 PST Path: supernews.google.com!sn-xit-03!supernews.com!news-feed.riddles.org.uk!arclight.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Please give me some hints... Date: 21 Mar 2001 13:18:36 -0500 Organization: NASA Goddard Space Flight Center Message-ID: References: <9909pn$19j2@tech.port.ac.uk> NNTP-Posting-Host: anarres.gsfc.nasa.gov MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 985199576 3538 128.183.220.71 (21 Mar 2001 18:32:56 GMT) X-Complaints-To: dscoggin@cne-odin.gsfc.nasa.gov NNTP-Posting-Date: 21 Mar 2001 18:32:56 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.6 Xref: supernews.google.com comp.lang.ada:5973 Date: 2001-03-21T18:32:56+00:00 List-Id: "WWM" writes: > I have written a program: input 2 integers, output sorted integers > one-by-one by descending order. e.g. > > > Input an integer: 2 > Input another one: 7 > > The sorted integer is: 7 6 5 4 3 2 > > > > The problem is, when I run it, it says: STORAGE_ERROR > num_of_integer : positive; type NUMBER_TYPE is array(POSITIVE range<>) of INTEGER; NUMBERS: NUMBER_TYPE(1..num_of_integer); --the array of numbers This code is your problem. Space for the variable NUMBERS is allocated at "elaboration time", which is before your code runs. So NUMBERS uses the value of 'num_of_integer', which is some random number, probably very large. > Can any one help??? You need to use a nested declare block: program unconstrained_sort is num_of_integer : positive; type NUMBER_TYPE is array(POSITIVE range<>) of INTEGER; ... begin Put("input an int"); get(max_int); put("input another"); get(min_int); num_of_integer := max_int - min_int; declare NUMBERS: NUMBER_TYPE(1..num_of_integer); begin -- call sort etc. end; end unconstrained_sort; Now 'num_of_integer' has a good value when it is used. -- -- Stephe