Array attributes give information about the array type or array variable.
Attribute | Meaning |
---|---|
'FIRST | the value of the smallest index |
'LAST | the value of the largest index |
'RANGE | the entire range of index values |
'LENGTH | the number of items in the array |
Given the following declarations (from recent examples):
max_iarr : constant := 8; -- largest index in int array min_farr : constant := 'a'; -- low index in float array max_farr : constant := 'h'; -- high index in float array subtype STRING8 is STRING (1 .. 8); type int_8_array is array (1 .. max_iarr) of INTEGER; type float_arrays is array (min_farr..max_farr) of FLOAT; type str_arrays is array (-5 .. 2) of STRING8; type small_arrays is array ('a' .. 'c') of FLOAT; arr1 : int_8_array; arr2 : float_arrays; arr3 : str_arrays; subtype lc_letters is CHARACTER range 'a' .. 'z'; type freq_table is array (lc_letters) of INTEGER; count : freq_table := (others => 0); -- freq counts
we have the following attribute values:
Array type/variable and attribute | Value |
---|---|
int_8_array'FIRST | 1 |
float_arrays'LAST | 'h' |
str_arrays'RANGE | -5 .. 2 |
arr3'LENGTH | 8 |
small_arrays'RANGE | 'a' .. 'c' |
small_arrays'LENGTH | 3 |
freq_table'RANGE | lc_letters |
'a' .. 'z' | |
count'RANGE | lc_letters |
A useful appplication of array attributes is setting the bounds of loop control variables:
for t in count'RANGE loop PUT(t); PUT(count(t), width=>11); NEW_LINE; end loop;
This causes "t" to take each index value in turn for the array "count", regardless of the index type and range.
The same attributes are used, with an index to show which dimension of the array is meant.
Attribute | Meaning |
---|---|
'FIRST(n) | the smallest value of the nth index |
'LAST(n) | the largest value of the nth index |
'RANGE(n) | the entire range of nth index values |
'LENGTH(n) | the number of items in the nth dimension of the array |