HP Pascal/iX Reference Manual (31502-90022)

11- 17
information that a long pointer requires.
Coercion from a long to a short pointer, in implementations where long
pointers point to a wider class of objects than short pointers, may
involve truncating the value of the long pointer. If this occurs, the
short pointer may not be able to address the original object pointed to
by the long pointer because of the short pointer's limited addressing.
This is an error. If range checking is on, this causes a run-time error.
Example
TYPE
integer_pointer = ^ integer;
real_pointer = ^ real;
VAR
ip : integer_pointer;
rp : real_pointer;
BEGIN
...
ip := integer_pointer( rp );
...
END;
Other Type Coercion.
All type coercions that do not fall under the categories of ordinal and
pointer type coercion can be viewed as the use of a free union, or
tagless variant record, where the implementation overlays the record
variants onto the same storage area.
The model for value type coercion:
type_1(expression)
is equivalent to the function call:
f_type_1(expression)
where f_type_1 is defined as:
FUNCTION f_type_1 (e: type_of_expression):type_1 ;
VAR
coerce_record : RECORD CASE Boolean OF
true: ( source_variant : type_of_expression );
false: ( target_variant : type_1 );
END;
BEGIN
coerce_record.source_variant := e;
f_type_1 := coerce_record.target_variant;
END;
The model for reference type coercion:
target_type ( source );
is equivalent to:
pointer_to_target_type ( addr ( source ) )
Whereas both ordinal and pointer type coercions may cause run-time errors
if the source values are not representable in the target type, the free
union form of type coercion never causes run-time errors.
Depending upon the source and target types, free union type coercion
consists of the following levels, listed in increasing order of freedom:
* Structural
* Representation
* Storage
* Noncompatible