Pointers
ptr[T] is mutable and nullable; const_ptr[T] is read-only and nullable. Arithmetic scales by pointee layout.
DByte 12.0 · Language
Contract§
pub struct Counter:
value: u32
fn increment(counter: ptr[Counter]) -> int:
(*counter).value = (*counter).value + (1 as u32)
return 0
pub fn kernel_main() -> int:
let counter = Counter(value = 41 as u32)
increment(&counter)
if counter.value != (42 as u32):
return 1
return 0
Source: source-examples/v12.0.0/pointers.dby
pub struct Counter:
value: u32
fn increment(counter: ptr[Counter]) -> int:
(*counter).value = (*counter).value + (1 as u32)
return 0
pub fn kernel_main() -> int:
let counter = Counter(value = 41 as u32)
increment(&counter)
if counter.value != (42 as u32):
return 1
return 0
Mechanics§
ptr[T] is mutable nullable raw storage; const_ptr[T] is read-only nullable raw storage. Arithmetic scales by pointee layout, with ptr[u8] reserved for byte addressing; dereference plus field projection remains a typed place.
Validation and failure§
Integer-pointer casts are explicit and pass through usize. Reverse const-to-mutable conversion, unknown fields, wrong pointee aggregates and immutable global stores are rejected.
Evidence and boundary§
Typed field-address IR and width-correct load/store disassembly prove that source-level pointer fields do not become ad hoc byte offsets.
Executable example§
pub struct Counter:
value: u32
fn increment(counter: ptr[Counter]) -> int:
(*counter).value = (*counter).value + (1 as u32)
return 0
pub fn kernel_main() -> int:
let counter = Counter(value = 41 as u32)
increment(&counter)
if counter.value != (42 as u32):
return 1
return 0