Ada Programming/Attributes/'Range

Description

X'Range is an Ada attribute that may be used in three ways.

If X is a discrete type, the X'Range represents the range of valid values for that type.

If X is an array type, then the attribute may be used with or without an input parameter Y. Y represents an index into the array type. The attribute represents the range of valid values for an index of X.

In all three cases, the X'Range is equivalent to X'First .. X'Last -- but X is only evaluated once.

↑Jump back a section

Example

If you declare:

type My_Enum is (Enum1, Enum2, Enum3);
type My_Array is array (MyEnum, Integer) of Boolean;

then

My_Enum'Range = Enum1 .. Enum3
My_Array'Range(1) = Enum1 .. Enum3
My_Array'Range(2) = Integer'First .. Integer'Last
My_Array'Range = My_Array'Range(1)
↑Jump back a section
Last modified on 5 January 2009, at 23:55