4. Arrays

In order to provide reuser with more flexibility, it is advisable to define generic type for the index of an array. See the following example.

generic

type Element is private;

type Vector is array ( Integer range <> ) of Element;

------------

This definition has a limitation over the index of an array, instead define another type to specify the index as shown below.

generic

type Element is private;

type Index is (<>);

type Vector is array ( Index range <> ) of Element;

------------

Guideline1 : Define index of an array as generic discrete type, thus provides flexibility over an array index.

Guideline2 : Define the element of an array as generic private type which can be defined for desired types. In other words parameterize the element type of an array as generic private type so that it is generalized.

Guideline3 : For non-generic units, define a constrained integer type for an array index with a constant parameter specifying maximum range so that it alone can be modified for new applications.

Max : constant integer := 250;

type Index is range 1 .. Max;

type Vector is array ( Index ) of Element;

Guideline4 : Always use an aggregate ( others ) in arrays and in records

in order to provide an association of component values

( supplying actuall values ) into a composite value of a

record or an array type. For example, see the following

composite type declarations in Ada.

Type Items is array ( Item ) of Boolean;

Type Set is record

The_Items : Items := Items' ( others => false );

end record;