Supplementing Generated Ada : Structured Elements : Enumerated Types

Enumerated Types

An Enumerated Type is a user-defined type with a finite number of values.

You cannot directly define a data item as an enumerated type. First, define the data item as a user-defined type, and then define the user-defined type as an enumerated type. You define the values for the enumeration in the “Definition’ field of the Properties by listing the values in brackets separated by commas. For example, {SUN,MON,TUE,WED}

Enumerated values and other textual items cannot have the same name within the same scope. For example, data-item SUN cannot be declared in the same chart where an enumerated value SUN is declared.

Note: Ada provides a way to define a subtype of an enumerated type. This subtype element usually can hold a subrange of enumeration values of the enumerated type. These types and subtypes can be related and used together in expressions. Run-time errors are issued when “out of range’ values are assigned to a subtype.

The definition of a subtype is only allowed for user-defined types, not for data-items.

There are two constant operators and five general operators for enumerated types:

 

Parameters to these constant operators are user-defined types that were defined as enumerated types.

 

Parameters to these operators are either enumerated values (literals) or variables. The T’VAL notation is used for non-unique literals.