Question

In existing ADA code, I found these two lines:

type SWITCH_TYPE is (TI1, TO3, TI2, TO1, TI3, TO2);
subtype TI_SWITCH_TYPE is SWITCH_TYPE range TI1..TI2;
subtype TO_SWITCH_TYPE is SWITCH_TYPE range TO1..TO2;

Is TO3 part of the TI_SWITCH_TYPE? Similarly, is TI3 part of TO_SWITCH_TYPE?

Was it helpful?

Solution

Yes, they are. The enum values are ordered in the way they are defined and you can have ranges like that. The names are of no consequence to the ordering.

OTHER TIPS

As above, but know that with Ada 2012, one can even define non-contiguous enumeration subtypes, e.g.:

type Animal is
 (Bear, Cat, Dog, Wolf, Horse);

subtype Pet is Animal
   with Static_Predicate => Pet in Cat | Dog | Horse;

Ada Rationale discussion on Subtype Predicates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top