3 ms·
That's incorrect. Ada has subtypes and new types for scalars and they behave differently. For example, a new integer type is: type MyInteger is integer; decla
by jonathanstrange 8y ago
That's incorrect. Ada has subtypes and new types for scalars and they behave differently. For example, a new integer type is:
type MyInteger is integer;
declares a new integer type that needs to be explicitly converted to any other integer type. You can also declare a new range integer type as in
type MyPositive is integer range 1 .. Integer'Last;
But you can also delcare integer and float subtypes:
subtype Day_Number is integer range 1 .. 31;
or (a bit pointless)
subtype MyInt is integer;
The difference between new types and subtypes is that no operations of the base type are defined for the new type since it's an entirely new type. A subtype on the other hand allows the operations of the base type, and their range is checked at compile time if possible and runtime if necessary.
In addition to this, Ada also has modular integer types, real types, floating point types, fixed point types, and decimal types in the numeric type system and all of them can be subtyped.
Of course, you can create a new type for any other type in Ada as well, but that's not what I meant when I was talking about integer subtypes.