comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Missing Index Value in Array Aggregate
Date: Wed, 26 Sep 2007 18:33:48 -0500
Date: 2007-09-26T18:33:48-05:00	[thread overview]
Message-ID: <fdeq3j$91r$1@jacob-sparre.dk> (raw)
In-Reply-To: 1190822071.488118.316450@y42g2000hsy.googlegroups.com

"Adam Beneschan" <adam@irvine.com> wrote in message
news:1190822071.488118.316450@y42g2000hsy.googlegroups.com...
...
> Note, though, that array *types* don't have bounds on their indexes.
> An array subtype is an array type plus (possibly) a constraint, where
> the constraint puts bounds on the indexes.  Once the type of the above
> aggregate is determined, the aggregate will have an (unnamed) subtype
> of that type with a constraint of (2..4).  Then, depending on what you
> do with that aggregate, the subtype will be *converted* to some other
> subtype.  If you declare an object:
>
>    type int4 is array(1..4) of integer;
>    A : int4 := (2 => 1010, 3 => 2020, 4 => 3030);

To expand on this a bit, in Ada 95, array bounds "slide" on assignment -
only the length of the array matters. So the bounds given in the aggregate
are not necessarily meaningful. The assignment

    type int3 is array(1..3) of integer;
    A : int3 := (2 => 1010, 3 => 2020, 4 => 3030);

is legal and does not raise Constraint_Error. Thus the number of cases where
you could tell statically that the aggregate is wrong is fairly few. There
are some, though; if the index values aren't continguous, the aggregate is
illegal:

    type int3 is array(1..3) of integer;
    A : int3 := (1 => 1010, 3 => 2020, 4 => 3030); -- Illegal.

And, as Adam points out, I'm not aware of any Ada compiler that doesn't put
out a warning when it knows an exception is going to be raised. Don't turn
off (or ignore) all warnings!

                                Randy.





  reply	other threads:[~2007-09-26 23:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-26 13:21 Missing Index Value in Array Aggregate Charles H. Sampson
2007-09-26 15:54 ` Adam Beneschan
2007-09-26 23:33   ` Randy Brukardt [this message]
2007-09-28  3:21     ` Charles H. Sampson
2007-09-28 10:05       ` Stephen Leake
2007-09-28 10:26         ` Ludovic Brenta
2007-09-28 16:21           ` Pascal Obry
2007-09-28 20:26             ` Maciej Sobczak
2007-10-03 17:01               ` roderick.chapman
2007-09-29 15:31         ` Charles H. Sampson
2007-09-30 11:02           ` Stephen Leake
replies disabled

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