aboutsummaryrefslogtreecommitdiff
path: root/docs/history/17-o3-boundaries/code/tests/arrays.zc
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /docs/history/17-o3-boundaries/code/tests/arrays.zc
a
Diffstat (limited to 'docs/history/17-o3-boundaries/code/tests/arrays.zc')
-rw-r--r--docs/history/17-o3-boundaries/code/tests/arrays.zc24
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/history/17-o3-boundaries/code/tests/arrays.zc b/docs/history/17-o3-boundaries/code/tests/arrays.zc
new file mode 100644
index 0000000..f8d46d8
--- /dev/null
+++ b/docs/history/17-o3-boundaries/code/tests/arrays.zc
@@ -0,0 +1,24 @@
+// growable arrays and fixed ones
+struct point { int x, y; };
+fn main()
+{
+ let before = live_objects();
+ {
+ []int a = new([]int);
+ for (int i = 0; i < 100; i++) push(a, i * i);
+ putn(len(a)); putc(' '); putn(cap(a)); putc(' '); putn(a[99]); putc(' ');
+ putn(pop(a)); putc(' '); putn(len(a)); putc(' ');
+ resize(a, 3); putn(len(a)); putc(' '); putn(a[2]); putc(' ');
+ fixed []int f = new(fixed []int, 5);
+ f[4] = 7; putn(f[4] + len(f)); putc(' ');
+ []point ps = new([]point, 2);
+ ps[1].y = 9; resize(ps, 10); putn(ps[1].y + len(ps)); putc(' ');
+ [8]int st; putn(len(st)); putc(' ');
+ []*point owned = new([]*point);
+ for (int i = 0; i < 20; i++) { *point p = new(point); p.x = i; push(owned, d*p); }
+ putn(owned[19].x); putc(' ');
+ putn(live_objects() - before); putc(10);
+ }
+ putn(live_objects() - before); putc(10);
+ return 0;
+}