Ada Programming/Attributes/'Range

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Ada Lovelace 1838.jpg

Contents


[edit] 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.

[edit] 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)

[edit] See also

[edit] Wikibook

[edit] Ada Reference Manual