[comp.lang.ada] Why one TYPE instead of the other?

FMOORE@eg.ti.COM (Freeman Moore - 575-3507) (09/25/87)

Okay, I seem to be overlooking something:

   type ONE is range 1 .. 10;                 -- type

           or

   type ONE is new INTEGER range 1 .. 10;     -- derived type

Why/When should I use one definition form instead of the other?

Thanks for any input,
Freeman Moore
FMOORE%eg.ti.com@relay.cs.net

stt@ada-uts (10/02/87)

The first form selects an underlying implementation
based on the range, which must be specified via *static*
expressions.   This form may fail at compile-time if
the requested range cannot be supported by any predefined
type.

The second form specifies that predefined INTEGER
be used as the underlying implementation type,
and the range may be specified by arbitrary, potentially
run-time, INTEGER expressions.
This form will never fail at compile-time, but
may raise Constraint_Error at run-time if the range you
specify is outside of Integer'FIRST .. Integer'LAST.

Based on the above characteristics, the first form
is preferable when legal, since it is not dependent
on the relative sizes of the various predefined integer types,
and detects out-of-range problems at compile-time.

But as noted, it cannot be used if the desired bounds
are not static (which implies compile-time-known) expressions.

S. Tucker Taft
Intermetrics, Inc.
Cambridge, MASS