Pointers & Slices
Pointer types
| Type | Meaning |
|---|---|
*T | Mutable pointer to T (nullable) |
*!T | Non-null mutable pointer to T |
*const T | Immutable pointer to T |
Taking an address
tape
var x: i64 = 42;
let ptr: *i64 = &x;Dereferencing
tape
let val: i64 = *ptr;
*ptr = 100;Dereference uses prefix * (same as C).
Arrays
Fixed-size, stack-allocated:
tape
let nums: [4]i64 = [1, 2, 3, 4];
let first = nums[0];
let count = nums.len; // compile-time constant: 4Slices
Bounded view into contiguous memory (pointer + length):
tape
var slice: []i64 = nums[1..3]; // elements at index 1, 2
let len = slice.len;
let full: []i64 = nums[..]; // full array as slice| Type | Meaning |
|---|---|
[]T | Mutable slice |
[]const T | Read-only slice |
Pointer arithmetic (t0/t1)
tape
var p: *u8 = &buffer;
let next: *u8 = (p as i64 + 1) as *u8; // byte-level offsetPointer arithmetic is done via casting to i64, adding the byte offset, and casting back. There is no automatic sizeof scaling.
Null checking
tape
let p: *i64 = get_maybe_null();
if (p != null) {
io.print_i64(*p);
}Non-null pointers
Not yet implemented
*!T and *const T are recognized in type declarations but not yet enforced — the typechecker does not reject null assignments to *!T or writes through *const T.tape
fn process(data: *!u8) {
// guaranteed non-null — no check needed
}Last modified: