The pointer type globalanyptr is assignment
compatible with every pointer type and the value nil.
Anyptr is another name for the same type, provided
for compatibility with older Pascals. This manual uses the term
globalanyptr exclusively, but anyptr
can be substituted wherever it appears.
A variable of type globalanyptr is not
bound to a specific pointer type. You can assign it any pointer-type
value, or compare it to any pointer-type value with the operator
= or >,
but you cannot dereference it.
Because a globalanyptr variable can be
assigned any pointer-type value, the compiler allocates it 64 bits.
If your program does not use extended address pointers, you can
save space by substituting localanyptr for
globalanyptr.
Your program uses extended address pointers if it declares
a type or variable with the EXTNADDR compiler option. Refer to the
HP Pascal/iX Reference Manual or the HP
Pascal/HP-UX Reference Manual, depending on your implementation,
for detailed information on compiler options.
Example
This program works the same way and takes the same amount
of space if you substitute anyptr for any or
every occurrence of globalanyptr. This would
be true even if the program had extended address pointers.
Since the program does not have extended address pointers,
it works the same way if you substitute localanyptr
for any or every occurrence of globalanyptr
— but it takes less space. (Compare this program with the
one in the section “LOCALANYPTR Variables ”.)
PROGRAM prog (input); TYPE iptr = ^integer; rec = RECORD f1, f2 : real; END; rptr = ^rec; VAR v1, d1 : iptr; v2, d2 : rptr; anyv : globalanyptr; 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 globalanyptr. 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. |