Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


3.5.5 Operations of Discrete Types

Static Semantics
(1)
For every discrete subtype S, the following attributes are defined:
(2)
S'Pos
(3)
           function S'Pos(Arg : S'Base)
             return universal_integer
(4)
(5)
S'Val
(6)
           function S'Val(Arg : universal_integer)
             return S'Base
(7)
Implementation Advice
(8)
For the evaluation of a call on S'Pos for an enumeration subtype, if the value of the operand does not correspond to the internal code for any enumeration literal of its type (perhaps due to an uninitialized variable), then the implementation should raise Program_Error. This is particularly important for enumeration types with noncontiguous internal codes specified by an enumeration_representation_clause.

(9)
(10)
(11)
(12)
(13)
          S'Val(S'Pos(X)) = X
          S'Pos(S'Val(N)) = N
Examples
(14)
Examples of attributes of discrete subtypes:
(15)
       --  For the types and subtypes declared in subclause 3.5.1 the following hold:
(16)
       --  Color'First   = White,   Color'Last   = Black
       --  Rainbow'First = Red,     Rainbow'Last = Blue
(17)
       --  Color'Succ(Blue) = Rainbow'Succ(Blue) = Brown
       --  Color'Pos(Blue)  = Rainbow'Pos(Blue)  = 4
       --  Color'Val(0)     = Rainbow'Val(0)     = White

Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12