Ada Programming/Attributes/'Pos

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Ada Lovelace 1838.jpg

Contents


[edit] Description

'Pos is a discrete type attribute. The attribute represents the integer position number of the value passed in as an input parameter. Position numbering starts at 0.

Note that representation clauses do not effect position numbering. Whatever underlying value the enumerated value has, the position number will remain the same.

[edit] Example

type My_Enum is  (Enum1, Enum2, Enum3); 
for  My_Enum use (Enum1 => 2, Enum2 => 4, Enum3 => 6);
...
pragma Assert (My_Enum'Pos(Enum1) = 2);  -- Wrong
pragma Assert (My_Enum'Pos(Enum1) = 0);  -- Right

[edit] See also

[edit] Wikibook

[edit] Ada Reference Manual