HP Pascal/iX Programmer's Guide (31502-90023)

4-: 5
const v_rec = rec[f1: hex('ffffffff')]; { bit52 constant field }
$pop$
begin
b := hex('ffffffff'); { compile-time error }
i := -1;
try
b := i; { run-time error }
recover ;
(
Example is continued on next page.
)
$push; type_coercion 'conversion'; range off$
b := bit52(i) + 1; { zero is stored }
b := bit52(hex('ffffffff'));
$pop$
try
i := b; { run-time error }
recover ;
try
i := b + i; { b and i are converted to longint and are }
{ too big to fit back into i }
recover ;
i := hex('ffffffff'); { both b and i now have all bits on }
{ the following never prints since i is sign extended to longint and
b is zero extended to longint }
$push; type_coercion 'conversion'$
if longint(i) = b then writeln('equal');
$pop$
end.
Shortint
The predefined data type
shortint
is an integer in the range
-32768..32767 that is stored in 16 bits. (In contrast, if you declare a
variable to be in that range, it is stored in 32 bits.) The type
shortint
has the following uses:
* If you want to access an external non-Pascal routine that has a
formal parameter of a type whose range is -32768..32767, and uses
16-bits of storage, you can declare a corresponding formal Pascal
parameter of type
shortint
, and it will be compatible.
* For Pascal/V compatibility.
To determine whether a type T is assignment compatible with the type
shortint
, you can treat
shortint
as a subrange of
integer
. This means
that you can assign a variable v of type T to a variable sv of type
shortint
if:
* The type T is
integer
or a subrange of
integer
.
* The value of v is within the range of
shortint
(-32768..32767).
If the ranges of T and
shortint
do not overlap, the assignment
sv:=v causes a compile-time error. If the ranges of T and
shortint
do overlap, but the value of v is outside the range of
shortint
the assignment sv:=v causes a run-time error.