References
In addition to pointers, Spice supports references. Under the hood, this works with non-nullable pointers.
Usage - local variables¶
References can not be declared without initializing. Only declaring with immediate initialization is valid:
Spice | |
---|---|
Whenever an assign operator is applied to the reference, not the reference is mapped to a new variable. Instead, the referenced value gets assigned. Therefore, the reference itself can only be assigned once, namely at declaration.
Usage - function parameters / return types¶
References can be used as function parameters and return types. This is useful for passing large objects without copying them:
Spice | |
---|---|
Usage - struct fields¶
Struct fields can also be of type reference: