HP Pascal/iX Programmer's Guide (31502-90023)
6- 7
recptr = ^rec;
VAR
small,
small2,
large,
default : recptr;
PROCEDURE p (r : rec); EXTERNAL;
BEGIN
new(small,a); {allocates only enough space for smaller variant, a}
new(small2,a); {allocates only enough space for smaller variant, a}
new(large,b); {allocates enough space for larger variant, b}
new(default); {allocates enough space for larger variant by default}
WITH small^ DO BEGIN
t := a;
a1 := 350;
a2 := 609;
END;
WITH large^ DO BEGIN
t := b;
b1 := 350;
b2 := 609;
END;
(
Example is continued on next page
.)
default^.t := a;
default^ := small^; {illegal}
default^.t := b;
default^ := large^; {illegal}
small2^ := small^ {still illegal even though the spaces are allocated }
{using the same tag }
small2^.a1 := small^.a1 {legal}
small2^.a2 := small^.a2 {legal}
p(small^); {illegal}
p(large^); {illegal}
p(default^); {legal}
END.
The pointer parameter of
new
can belong to a PACKED structure.
Example 6
PROGRAM prog;
TYPE
ptr = ^integer;
pa = PACKED ARRAY [1..10] OF ptr;
pr = PACKED RECORD
f1,f2 : ptr;
END;
VAR
v1 : pa;
v2 : pr;
BEGIN
new(v1[5]);
new(v2.f1);
END.
A pointer created by
new
can be compared to another pointer for equality
or inequality only. This is also true of a pointer created by
mark
. For
more information on relational operators, refer to the
HP Pascal/iX
Reference Manual
or the
HP Pascal/HP-UX Reference Manual
, depending on
your implementation.