Ada Programming/Attributes/'First

From Wikibooks, open books for an open world
Jump to: navigation, search

Ada Lovelace 1838.jpg

Description[edit]

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.

Example[edit]

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!

See also[edit]

Wikibook[edit]

Ada Reference Manual[edit]