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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2507b6d982782e45 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: [Q] Problem with Array Concatenation? Date: 1997/07/10 Message-ID: #1/1 X-Deja-AN: 256088071 References: <33c280c8.418253@news.demon.co.uk> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-07-10T00:00:00+00:00 List-Id: In article <33c280c8.418253@news.demon.co.uk>, john@assen.demon.co.uk (John McCabe) wrote: >procedure Test is > type Arr_Type is array (1 .. 100) of Integer; > > Src_Array : Arr_Type; > Dst_Array : Arr_Type; >begin > for Index in 1 .. 100 loop > Src_Array (Index) := Index; > end loop; > Dst_Array := (others => 0); > > Dst_Array := Src_Array (51 .. 100) & Src_Array (1 .. 50); >end Test; As Tuck pointed out, the concatenation will raise Constraint_Error, even though this is a legal Ada program. But even in Ada 83, there is a simple fix: make the array type unconstrained: declare type AT is array (Positive range <>) of Integer; SA : AT (Positive range 1 .. 100); DA : AT (SA'Range); begin for Index in SA'Range loop SA (Index) := Index; end loop; DA := SA (51 .. 100) & SA (1 .. 50); end; There's another way to make the fix, by manually sliding the initial substring: declare type AT is array (Positive range 1 .. 100) of Integer; SA : AT; DA : AT; subtype Slided is AT (1 .. 50); begin ... DA := Slided (SA (51 .. 100)) & SA (1 .. 50); end; In Ada 83 the 2nd substring will be automatically slided. - Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271