The pointer type localanyptr is similar
to the type globalanyptr (or anyptr)
in that it is assignment compatible with every pointer type and
the value nil.
A localanyptr variable differs from a
globalanyptr variable in that the compiler
allocates it 32 bits instead of 64 bits. If your program does not
use extended address pointers, you can save space by using localanyptr
instead of globalanyptr.
Like a globalanyptr variable, a localanyptr
variable is not bound to a specific pointer type. You can assign
it any pointer-type value, but you can not assign it an extended
address pointer that cannot be converted to a 32-bit value.
You can compare a localanyptr variable
to any pointer-type value (even one that you cannot assign to it)
with the operator =
or >.
You cannot dereference a localanyptr.
Example
This program is the same as the one in the section “GLOBALANYPTR Variables ”, except that localanyptr
replaces every occurrence of globalanyptr.
The two programs work the same way, but this one takes less space.
PROGRAM prog (input); TYPE iptr = ^integer; rec = RECORD f1, f2 : real; END; rptr = ^rec; VAR v1, d1 : iptr; v2, d2 : rptr; anyv : localanyptr; b : Boolean; BEGIN {Initialize v1 and v2} new(v1); new(v2); v1^ := 0; WITH v2^ DO BEGIN f1 := 0; f2 := 0; END; {Set anyv to v1 or v2, depending on b} read(b); IF b THEN anyv := v1 ELSE anyv := v2; {You cannot dereference anyv, because it is a localanyptr. This is how you can access its data:} IF anyv = v1 THEN BEGIN d1 := anyv; d1^ := d1^ + 1; END ELSE BEGIN d2 := anyv; WITH d2^ DO BEGIN f1 := 34.6; f2 := 91.2; END; END; END. |