yorick banner

Home

Manual

Packages

Global Index

Keywords

Quick Reference

Yorick Function Reference

Using Pointers

A scalar of type pointer points to a Yorick array of any data type or dimensions. Unary & returns a pointer to its argument, which can be any array valued expression. Unary * dereferences its argument, which must be a scalar of type pointer, returning the original array. A dereferenced pointer may itself be an array of type pointer. The unary & and * bind more tightly than any other Yorick operator except . and -> (the member extraction operators), and array indexing x (..):

&expr    return a scalar pointer to expr
*expr    dereference expr, a scalar pointer

Since a pointer always points to a Yorick array, Yorick can handle all necessary memory management. Dereference * or ->, copy by assignment =, or compare to another pointer with == or != are the only legal operations on a pointer. A pointer to a temporary expr makes sense and may be useful.

The purpose of the pointer data type is to deal with several related objects of different types or shapes, where the type or shape changes, making struct inapplicable.