3.6.1 Index Constraints and Discrete Ranges
1
An
index_constraint
determines the range of possible values for every index of an array subtype,
and thereby the corresponding array bounds.
Syntax
2
3
Name Resolution Rules
4
4.a
Legality Rules
5
Static Semantics
6
Dynamic Semantics
7
An
index_constraint
is
compatible with an unconstrained array subtype if and only
if the index range defined by each
discrete_range
is compatible (see
3.5) with the corresponding
index subtype.
If any of the
discrete_ranges
defines a null range, any array thus constrained is a
null array,
having no components.
An array value
satisfies
an
index_constraint
if at each index position the array value and the
index_constraint
have the same index bounds.
7.a
Ramification: There is no need to define
compatibility with a constrained array subtype, because one is not allowed
to constrain it again.
8
9
10
49 Even if an array value does not satisfy
the index constraint of an array subtype, Constraint_Error is not raised
on conversion to the array subtype, so long as the length of each dimension
of the array value and the array subtype match. See
4.6.
Examples
11
Examples of array
declarations including an index constraint:
12
Board : Matrix(1 .. 8, 1 .. 8); --
see 3.6
Rectangle : Matrix(1 .. 20, 1 .. 30);
Inverse : Matrix(1 .. N, 1 .. N); --
N need not be static
13
Filter : Bit_Vector(0 .. 31);
14
Example of array
declaration with a constrained array subtype:
15
My_Schedule : Schedule; -- all arrays of type Schedule have the same bounds
16
Example of record
type with a component that is an array:
17
type Var_Line(Length : Natural) is
record
Image : String(1 .. Length);
end record;
18
Null_Line : Var_Line(0); -- Null_Line.Image is a null array
Extensions to Ada 83
18.a
We allow the declaration
of a variable with a nominally unconstrained array subtype, so long as
it has an initialization expression to determine its bounds.
Wording Changes from Ada 83
18.b
18.c
The rules given in RM83-3.6.1(5,7-10), which
define the bounds of an array object, are redundant with rules given
elsewhere, and so are not repeated here. RM83-3.6.1(6), which requires
that the (nominal) subtype of an array variable be constrained, no longer
applies, so long as the variable is explicitly initialized.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe