Pointers — T->, <-, ->, ., @
Overview
T-> is the pointer-to-T type constructor. Pointer values are used for
address-of operations, pointer-member access, wild/wildx interop, and C FFI
boundaries. The detailed region and ABI policy is in
memory/pointers.md; this page is the short syntax
reference.
Pointer Operators
| Operator | Meaning |
|---|---|
@ |
Address-of (get pointer to variable) |
. |
Direct member access on struct values |
-> |
In type: pointer to T. In expression: dereference pointer then access field |
<- |
Dereference (get entire value from pointer) |
?. |
Safe navigation (NIL-safe member access) |
@ptr_add<T> / @ptr_sub<T> |
Unsafe pointer arithmetic behind use "unsafe.npk".*; |
Member Access: . vs ->
. accesses a field on a struct value directly. It does not auto-dereference pointers.
-> dereferences a pointer to a struct, then accesses the field. Equivalent to
(<-ptr).field.
<- dereferences a pointer and returns the entire value.
struct:Point = { int32:x; int32:y; };
// Direct struct — use .
Point:p = Point { x: 10, y: 20 };
int32:px = p.x; // direct member access
// Pointer to struct — use -> for fields, <- for whole value
Point->:ptr = @p;
int32:px2 = ptr->x; // dereference + field access
Point:copy = <-ptr; // dereference entire struct
// Pointer indexing then . access
// [0] on a pointer dereferences at offset 0, yielding a struct value
// then . accesses the field on that value
HashMap->:map = get_map();
int64:len = map[0].length; // index deref + direct field access
Wild Pointers
wild int32:x = 42; // unmanaged allocation
int32->:ptr = @x; // pointer to x
int32:val = <-ptr; // dereference
wild memory is not garbage collected. You must manage it manually or use defer
for cleanup.
As of v0.32.5, raw pointer arithmetic is available only behind the narrow
stdlib/unsafe.npk gate and only for wild/wildx pointers:
use "unsafe.npk".*;
func:same = int32(wild int32->:p) {
int32->:q = @ptr_add<int32>(p, 0i64);
pass <-q;
};
stack/default-local pointers and gc pointers are rejected for pointer
arithmetic even with the gate. @NULL is rejected statically, while <- NULL
and NULL->field dispatch the NULL failsafe sentinel 46 at runtime.
Executable Memory — wildx
wildx allocates executable memory for JIT compilation:
wildx uint8->:code = wildx_alloc(4096); // 4KB executable page
Safe Alternative: Handle
For arena-allocated data, prefer Handle<T> over raw pointers. See
memory_model/handle.md.
Related
- memory/pointers.md — v0.32.x pointer policy and C ABI table
- memory/wild.md — wild allocation mode
- handles/README.md — generational handles
- functions/extern.md — FFI pointer patterns