Pointers
Spice supports pointers by providing the address-of operator & and indirection operator *.
For any primitive or custom data type you can also use the respective pointer type. For the int type, the pointer type is int*.
Usage¶
See an example here:
| Spice | |
|---|---|
Here is a more complex example where pointers are used to pass a reference of a person to a procedure and modify a field.
| Spice | |
|---|---|
Multiple pointers
Spice also supports the usage of double, triple, ... pointers like char*** or types like int*[]*. Please use such types sparingly and only where necessary, due to readability reasons.
To get the pointer to the pointer to an integer, you can use &&intVariable and **doubleIntPtr in reverse.
The member access operator automatically de-references the left side, no matter how many indirections there are.