comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: [Q] Problem with Array Concatenation?
Date: 1997/07/09
Date: 1997-07-09T00:00:00+00:00	[thread overview]
Message-ID: <ED2nMH.4uo.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 33c280c8.418253@news.demon.co.uk


John McCabe (john@assen.demon.co.uk) wrote:

: I would appreciate confirmation on whether the following piece of code
: is legal Ada 83, and what the effect should be (obviously I haven't
: bothered with Text_IO for outputting results, but what should happen
: when I compile this?).

This is legal Ada 83, but will raise Constraint_Error at run-time,
because the result of the concatenation (before "sliding" happens)
has a high bound of 150, which is outside the index subtype (which
goes only from 1 up to 100) -- see paragraph RM83 4.5.3(6).

In Ada 95, it would do the "expected," and give you an array with the
values (51,52, ...,100,1,2,..., 50).  This is thanks to paragraph
RM95 4.5.3(6), which specially handles the case when the array
type was defined by a constrained_array_definition, and essentially
"pre-slides" the result, so the result of the concatenation has
the bounds 1..100 rather than 51..150.

This is one of those little annoyances from Ada 83 which we
"fixed" in Ada 95.  (I quote "fixed" because there are probably
still those who find the Ada 83 approach in some sense to have
more "purity of essence" -- aka POE for those Dr. Strangelove fans.)

: -----------
: 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;
: -----------

: Thanking you in advance.


: Best Regards
: John McCabe <john@assen.demon.co.uk>

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




  parent reply	other threads:[~1997-07-09  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-07-08  0:00 [Q] Problem with Array Concatenation? John McCabe
1997-07-08  0:00 ` Michael Quinn
1997-07-09  0:00 ` Tucker Taft [this message]
1997-07-10  0:00 ` Matthew Heaney
1997-07-11  0:00   ` Tucker Taft
1997-07-11  0:00     ` Matthew Heaney
1997-07-13  0:00     ` Robert A Duff
1997-07-13  0:00       ` John McCabe
1997-07-13  0:00     ` Keith Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox