From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Please give me some hints...
Date: 21 Mar 2001 13:18:36 -0500
Date: 2001-03-21T18:32:56+00:00 [thread overview]
Message-ID: <upufbkmtf.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 9909pn$19j2@tech.port.ac.uk
"WWM" <wwminirl@hotmail.com> 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
prev parent reply other threads:[~2001-03-21 18:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <9909pn$19j2@tech.port.ac.uk>
2001-03-17 22:51 ` Please give me some hints chris.danx
2001-03-17 23:10 ` chris.danx
2001-03-21 18:18 ` Stephen Leake [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox