HP Pascal/iX Reference Manual (31502-90022)

11- 19
$PUSH, TYPE_COERCION 'REPRESENTATION'$
WRITE( hex_digit[ nibble_array( n )[i] ] );
$POP$
END;
In the above example, the integer n is treated as an array of nibbles in
order to extract each nibble sequentially and write out its value in
hexadecimal. Since representation type coercion guarantees that the
source and target types are identical in size, the compiler can guarantee
that the entire integer is covered by the nibble array: there are no
bits missed.
Storage. A type coercion expression is considered to be
storage
type
coercion, if the size of the storage allocated for the source is greater
than the size of the storage allocated for the target type.
Storage type coercion guarantees that no nonexistent memory is accessed
and that no undefined bits are accessed.
The following illustrates storage type coercion. The compiler guarantees
that PROC never accesses a part of its formal parameter that is not
actually part of the actual parameter. This is because the actual
parameter is guaranteed to be larger than or the same size as the formal
parameter.
Example
TYPE
string_1 = STRING [255];
string_2 = STRING [80]
VAR
s1 : string_1;
s2 : string_2;
...
PROCEDURE PROC (VAR S : STRING_2);
BEGIN
...
END;
...
$PUSH, TYPE_COERCION 'STORAGE'$
PROC ( string_2 (s1) );
$POP$
Noncompatible. Noncompatible type coercion permits anything to be
coerced to anything. There is no guarantee that the accessed storage
exists, nor that there is any accessible storage.
Example
FUNCTION non_protected_space: integer;
TYPE
big_index = 0..max_array_size-1;
big_array = array[big_index] of integer;
VAR
idx : big_index;
int : integer;
BEGIN
idx := 0;
TRY
WHILE (idx <= max_array_size-1) DO BEGIN
$PUSH, TYPE_COERCION 'NONCOMPATIBLE'$
int := big_array( int )[idx];
$POP$
idx := idx + 1;
end;
non_protected_space := max_array_size-1;
RECOVER