From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: looping through variable length array
Date: 18 Mar 2002 16:18:25 -0500
Date: 2002-03-18T21:23:45+00:00 [thread overview]
Message-ID: <uit7tr2vy.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 3c96047c$1@pull.gecm.com
"Stephen Frackelton" <stephen.frackelton@baesystems.com> writes:
> i'm attempting to loop through a set of arrays, but theses arrays are of
> different lengths to cater for various message sizes.
> but i want to write the loop only once to cater for this.
> how is the best way to model this ?
Attributes!
procedure Loop_Thru_Array (Item : in Some_Array_Type)
is begin
for I in Item'range loop
...
end loop;
end Loop_Thru_Array;
> can i somehow use an unconstrained array ?
Yes. To make different sized array objects all of the same type, you
use an unconstrained array type.
type Some_Array_Type is array (Some_Index_Type range <> ) of Whatever_Type;
> if i have my data available in a fixed size array, how can i get
> this variable into a format i can loop through, regardless of the
> size of the array.
Use a slice.
Fixed_Data : Some_Array_Type (1 .. 100);
Fixed_Data_Last : Some_Index_Type := 50;
-- Suppose only 1 .. Fixed_Data_Last has real data
Loop_Thru_Array (Fixed_Data (1 .. Fixed_Data_Last));
Hope this helps.
--
-- Stephe
next prev parent reply other threads:[~2002-03-18 21:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-18 15:16 looping through variable length array Stephen Frackelton
2002-03-18 15:40 ` Larry Hazel
2002-03-18 17:47 ` Stephen Frackelton
2002-03-18 18:53 ` Larry Hazel
2002-03-18 15:57 ` Martin Dowie
2002-03-18 21:18 ` Stephen Leake [this message]
2002-03-19 18:21 ` Bobby D. Bryant
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox