Unsigned integer types are not predefined types AI-00402/07 1
89-06-16 ra WA
| !standard 03.05.04 (07) 89-06-16 AI-00402/07
!class ramification 85-12-03
| !status WG9-approved 89-06-16
!status ARG-approved 88-01-30 (reviewed)
!status ARG-approved 88-10-31 (11-0-0) (pending editorial review)
!status work-item 86-10-05
!status received 85-12-03
!references AI-00597, 83-00684, 83-00700
| !topic Unsigned integer types are not predefined types
!summary 86-10-05
An unsigned integer type cannot be one of the predefined integer types.
!question 86-10-05
3.5.4(7) says:
The predefined integer types include the type INTEGER. An
implementation may also have predefined types such as SHORT_
INTEGER and LONG_INTEGER, which have (substantially) shorter and
longer ranges, respectively, than INTEGER. The range of each of
these types must be symmetric about zero, excepting an extra
negative value which may exist in some implementations.
Does the phrase "each of these types" refer just to predefined types having
names of the form INTEGER, SHORT_INTEGER, LONG_INTEGER, etc.? If so, can
other predefined types have a non-symmetric range, and in particular, a range
that only includes non-negative values?
!response 86-10-05
As the first sentence of 3.5.4(7) states, the paragraph is discussing "the
predefined integer types," so when the paragraph refers to "these types," it
is referring to all predefined integer types, not just types whose names have
the form SHORT_INTEGER, LONG_INTEGER, LONG_LONG_INTEGER, etc. Consequently,
an unsigned integer type cannot be one of the predefined integer types.
The question of whether a predefined integer type could be an unsigned type
was addressed during the design of the language. 3.5.4(7) reflects the
decision that it was undesirable to allow such types. If such types were
allowed, there could be surprising consequences for application programmers.
For example, consider the type declaration:
type UNS is range 1..10;
Suppose an implementation did support a predefined integer type with an
unsigned representation. Should this type be chosen as the base type for
UNS, or should some integer type with a symmetric range be chosen? If the
unsigned base type were chosen, CONSTRAINT_ERROR or NUMERIC_ERROR would be
raised for any numeric operations that produced a negative value. Such
implementation-dependent behavior was considered undesirable.
Unsigned integer types are not predefined types AI-00402/07 2
89-06-16 ra WA
In addition, consider the meaning and potential use of SYSTEM.MAX_INT, which
is defined to be "The largest (most positive) value of all predefined integer
types" (13.7.1(3)). If an unsigned predefined integer type exists,
presumably the following type definition can be rejected, since there need be
no predefined type that covers the range MIN_INT .. MAX_INT:
type MAX is range SYSTEM.MIN_INT .. SYSTEM.MAX_INT;
If unsigned predefined integer types were intended to be allowed, additional
SYSTEM constants would have been defined so as to adequately characterize the
set of permitted integer type declarations.
Finally, 4.10(5) specifies how an implementation is to evaluate nonstatic
universal integer expressions:
For the evaluation of an operation of a nonstatic universal
expression, an implementation is allowed to raise the exception
NUMERIC_ERROR only if the result of the operation is ... an
integer value greater than SYSTEM.MAX_INT or less than
SYSTEM.MIN_INT.
If an unsigned predefined integer type exists such that SYSTEM.MAX_INT is,
say, approximately twice ABS(SYSTEM.MIN_INT), an implementation will have
considerable difficulty in evaluating nonstatic universal integer expressions
at run time, since it will have no type that covers the range SYSTEM.MIN_INT
to SYSTEM.MAX_INT. The wording in 4.10(5) therefore further shows that it
was not the intent to allow unsigned predefined integer types.