Ada Programming/Attributes/'Last

From Wikibooks, open books for an open world
< Ada Programming‎ | Attributes
Jump to: navigation, search

Ada Lovelace 1838.jpg


X'Last, where X is any scalar type (for example integer, enumerated, real), is an attribute that represents the last value (upper bound) in the range of type X. The value returned is of type X.

A'Last, where A is an array, denotes the last index value. For more-dimensional arrays, A'Last(N) denotes the last index value of the Nth dimension (N must be static).


type My_Enum is (Enum1, Enum2, Enum3);
type My_Int  is range -1 .. 5;
pragma Assert (My_Enum'Last = Enum3);  -- OK
pragma Assert (My_Int'Last  = 5);      -- OK
pragma Assert (My_Int'Last  = 4);      -- Wrong!

See also[edit]


Ada Reference Manual[edit]