문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top