Previous: , Up: Data Classes   [Contents][Index]


6.2.12 Pointers to Variables and Routines

There are two kinds of pointers: A variable pointer points at another variable, and a function pointer points at a function or routine. Pointers act as aliases of whatever they point at. Define a pointer by prefixing an ampersand & to the name of the entity it is to point at, or by using the routine pointer (pointer). For example, pointers to a variable y and a function sin are defined as follows:

y = [ 1, 2, 3 ]
z = &y
q = &SIN
POINTER, r, y

A variable pointer shares the data memory of the entity it points at. If you assign a value to a variable pointer or to the entity it points at, then the change is reflected in the other member of the pair as well. For instance, after the above assignments y(1), z(1), and r(1) all yield the value 2, and after the assignment y = 17, all three refer to the value 17.

A function pointer acts in every way like the function or routine it points at. For instance, with the assignments mentioned above, SIN(1) and q(1) both yield the same result.

If you use DELETE,z on pointer z defined above, then z still points at y, but now y has data class undefined (Undefined). If you use ZAP,z, then y is removed completely, and pointer z points at nothing. To break the link between the pointer and whatever it points at, use DELETE,/POINTER,z. This command makes z undefined, but leaves whatever z pointed at unchanged. To remove pointer z completely, use ZAP,/POINTER,z. This, too, leaves whatever z pointed at unchanged. To merely change the target of the pointer, use the pointer routine.


Previous: , Up: Data Classes   [Contents][Index]