HP Pascal/iX Programmer's Guide (31502-90023)
4-: 3
b16 := v1; {legal}
b16 := b16 + 5; {legal; now b16 = (65540 MOD 65535) = 4}
b16 := b16 - 5; {legal; now b16 = 65535}
v3 := 65535;
v3 := v3 + 4; {causes run-time error}
v3 := 4;
v3 := v3 - 5; {causes run-time error}
v1 := -20;
b16 := v1; {causes run-time error}
v2 := -30;
b16 := v2; {causes compile-time error}
END. {prog}
Bit32
The predefined data type
bit32
is a subrange, 0..232-1, that is stored in
32 bits.
bit32
is a unique HP Pascal type because arithmetic operations
on
bit32
data are performed as unsigned 32-bit integers. Unsigned
addition and subtraction do not overflow. Unsigned multiply can overflow
unless the compiler option OVFLCHECK is used.
Note that there are no
bit32
constants in the compiler. Therefore,
numbers in the range maxint + 1..232 -1 can not be expressed directly.
The function hex can be used with the compiler options TYPE_COERCION and
RANGE to provide
bit32
constants. The compiler option TYPE_COERCION is
also needed when initializing a
bit32
constant field. In this case,
bit32() is not used. When
bit32
is used in an executable statement,
RANGE OFF must be used.
To determine if a type T is assignment compatible with
bit32
:
* If variable v is of type T and variable b32 is of type bit32, then
the assignment b32 := v is legal if the value of v is within the
range 0..232-1.
* If the ranges of T and bit32 do not overlap, the assignment b32 :=
v causes a compile-time error.
* If the ranges of T and bit32 do overlap, but the value of v is
outside the range of bit32, then the assignment b32 := v causes a
run-time error.
Example
$standard_level 'hp_modcal'$
program prog_bit32(output);
var i : integer;
b : bit32;
type rec = record
f1 : bit32;
end;
$push; type_coercion 'conversion'$
const v_rec = rec[f1: hex('ffffffff')]; { bit32 constant field }
$pop$
begin
b := hex('ffffffff'); { compile-time error }
i := -1;
try
b := i; { run-time error }
recover ;
$push; type_coercion 'conversion'; range off$