comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nickroberts@blueyonder.co.uk>
Subject: Re: What is happening Here?Totally clueless
Date: Tue, 19 Aug 2003 16:06:37 +0100
Date: 2003-08-19T16:06:37+01:00	[thread overview]
Message-ID: <bhtedu$30am8$1@ID-25716.news.uni-berlin.de> (raw)
In-Reply-To: d40d7104.0308190522.4b631227@posting.google.com

"prashna" <vashwath@rediffmail.com> wrote in message
news:d40d7104.0308190522.4b631227@posting.google.com...

>    array1 := (others => 0);
>    array1(1..2) := array_local'(others => (2));
>                        ^^^^ can anybody what exactly is this?why they
> are not assigning directly to 2 without doing this(Typecast????)

This is a qualification that it being used, as a special syntactic
construction, as an array aggregate (of a specific subtype).

> When I execute a constraint error is being raised.Can any body explain
> what is going on here.

The specific subtype in this case -- array_local -- has length 10, whereas
the destination array -- array1 -- as length 2. When assigning an array
value to an array variable (of the same type but different subtypes), the
value and variable must be of the same length.

In fact, they do not have to have the same bounds. If they are the same
length but of different bounds, the value 'slides' into the variable (the
variable's bounds do not change). An anonymous array aggregate with
indefinite length (because it contains 'others') automatically assumes the
length of the destination. Thus the following are legal declarations and
statements:

   declare
      array2: array_unconstrained(11..20);
      subtype array_small is array_unconstrained(1..5);
   begin
      array1 := array_local'(others => 0); -- slides 1..10 -> 11.20
      array1(1..2) := (others => 2); -- assumes length 2
      array2 := array1; -- slides 1..10 -> 11.20
      array2(12..16) := array_small'(others => 3); -- slides 1..5 -> 12..16
   end;

> Thanks in advance,

Hope This Helps.

--
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]






  parent reply	other threads:[~2003-08-19 15:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-19 13:22 What is happening Here?Totally clueless prashna
2003-08-19 14:36 ` steveo
2003-08-19 15:06 ` Nick Roberts [this message]
2003-08-20  8:34   ` prashna
2003-08-20 20:45     ` Simon Wright
2003-08-20 22:00       ` chris
replies disabled

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