HP Pascal/iX Reference Manual (31502-90022)

11- 18
Structural. A type coercion expression is considered to be
structural
if
the following are true:
* The bitsizes of the source and target types are the same.
* The alignment of the source and target types are the same.
* The source and target types are compatible.
* If the source and target are structured, then the corresponding
component in the two structures obey the above three rules of
bitsizes, alignment and compatibility.
Structural type coercions are enabled by specifying 'STRUCTURAL' in the
compiler option TYPE_COERCION.
Structural type coercion is essentially a renaming of the components of a
structure. Because the component types are guaranteed to be the same,
the storage allocated for the source and target types is also the same,
and reinterpreting the storage of the source as if it was of the target
type will produce correct results.
Example
$TYPE_COERCION 'STRUCTURAL'$
...
TYPE
source_t = RECORD
i : integer;
b : false..true;
end;
target_t = RECORD
j : minint..maxint;
c : Boolean;
END;
VAR
source : source_t;
target : target_t;
...
BEGIN
...
target := target_t(source);
...
END;
In the above example, the two record types are the same: their bitsizes
are identical and their corresponding components are the same.
Representation. A type coercion expression is considered to be
representation
type coercion if the bitsizes of the source and target
types are the same. The internal structure of structured types for
either the source or target does not matter.
Representation type coercions are enabled by specifying 'REPRESENTATION'
in the compiler option TYPE_COERCION.
Example
$STANDARD_LEVEL 'HP_MODCAL'$
PROCEDURE write_hex( n : integer );
TYPE
nibble_array = PACKED ARRAY[0..7] OF 0..15;
hex_digit_t = array [0..15] OF char;
CONST
hex_digit = hex_digit_t[ '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' ];
VAR
i : 0..7;
BEGIN
FOR i := 0 to 7 DO