Book creator (disable)

Ada Programming/Attributes/'First

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Ada Lovelace 1838.jpg

Contents


[edit] Description

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

Note that the Ada attribute X'Pos(0) is not necessarily equivalent to X'First. The underlying position numbers of type X may follow an unusual convention.

[edit] Example

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

[edit] See also

[edit] Wikibook

[edit] Ada Reference Manual