nx_bounds_ok.nx source
↩ module page · 14 lines · 535 B
1// in-bounds fixed-array access + runtime index must still build+run. Expect BOUNDS_OK.
2import "nx_syscalls.nx"
3func main() -> i64 {
4 var a: [4]i64
5 a[0] = 10
6 a[3] = 40 // in bounds (3 < 4)
7 let x: i64 = a[3] // in-bounds const read
8 var i: i64 = 0
9 var s: i64 = 0
10 while i < 4 { s = s + a[i]; i = i + 1 } // runtime index -> unchecked, still works
11 if x == 40 { sys_write(1, "BOUNDS_OK\n" as *u8, 10) } else { sys_write(1, "BOUNDS_BAD\n" as *u8, 11) }
12 sys_exit(0)
13 return 0
14}