Ada Programming/Attributes/'Pos

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.

↑Jump back a section

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
↑Jump back a section
Last modified on 5 January 2009, at 23:53