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

4: 6
Example
PROGRAM prog;
TYPE
T1 = integer; {overlaps shortint range}
T2 = -10..40000; {overlaps shortint range}
T3 = 40000..50000; {does not overlap shortint range}
VAR
v1 : T1; {sv:=v1 may be legal, depending on value of v1}
v2 : T2; {sv:=v2 may be legal, depending on value of v2}
v3 : T3; {sv:=v3 is never legal}
sv : shortint;
BEGIN
v1 := 10;
sv := v1; {legal assignment}
v1 := 45000;
sv := v1; {causes run-time error}
v2 := 400;
sv := v2; {legal assignment}
v2 := 35000;
sv := v2; {causes run-time error}
v3 := 40000;
sv := v3; {causes compile-time error}
END.
Longint
The predefined data type
longint
is an integer in the range -263..263-1
that is stored in 64 bits. The compiler option OVFLCHECK has no effect
on 64 bit multiply.
Note that there are no
longint
constants in the compiler. Therefore,
numbers outside of the range minint .. maxint can not be expressed
directly. The compiler option TYPE_COERCION must be used with a run-time
computation. If the numbers are constants, they must be typed coerced to
longint
so they do not integer overflow.
Example
$standard_level 'hp_modcal'$
program prog_longint(output);
var i : integer;
b : longint;
type rec = record
case integer of
0:(l : longint);
1:(f1,f2: integer);
end;
const v_rec = rec[f1: hex('1'),
f2: hex('ffffffff')]; { longint constant field }
begin
b := v_rec.l;
writeln(b);
try
i := b; { run-time error }
recover ;
$push; type_coercion 'conversion'$