Next: , Previous: , Up: Implementation Defined Attributes   [Contents][Index]


4.21 Attribute Enum_Rep

For every enumeration subtype S, S'Enum_Rep denotes a function with the following spec:

function S'Enum_Rep (Arg : S'Base) return <Universal_Integer>;

It is also allowable to apply Enum_Rep directly to an object of an enumeration type or to a non-overloaded enumeration literal. In this case S'Enum_Rep is equivalent to typ'Enum_Rep(S) where typ is the type of the enumeration literal or object.

The function returns the representation value for the given enumeration value. This will be equal to value of the Pos attribute in the absence of an enumeration representation clause. This is a static attribute (i.e.,:the result is static if the argument is static).

S'Enum_Rep can also be used with integer types and objects, in which case it simply returns the integer value. The reason for this is to allow it to be used for (<>) discrete formal arguments in a generic unit that can be instantiated with either enumeration types or integer types. Note that if Enum_Rep is used on a modular type whose upper bound exceeds the upper bound of the largest signed integer type, and the argument is a variable, so that the universal integer calculation is done at run time, then the call to Enum_Rep may raise Constraint_Error.