aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/alias.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 /tests/programs/alias.zc
a
Diffstat (limited to 'tests/programs/alias.zc')
-rw-r--r--tests/programs/alias.zc21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/programs/alias.zc b/tests/programs/alias.zc
new file mode 100644
index 0000000..2ebc3e5
--- /dev/null
+++ b/tests/programs/alias.zc
@@ -0,0 +1,21 @@
+// a pointer computed from a live object is a borrow of it: fine while the owner lives
+struct node { int v; node* next; };
+fn main() {
+ let p = new(4);
+ p[0] = 11; p[1] = 22;
+ let q = p + 1;
+ put_n(q[-1]); put_c(' ');
+ put_n(q[0]); put_c(' ');
+ node* a = new(node), b = new(node);
+ a.v = 3; b.v = 4; a.next = b;
+ node* c = a.next;
+ put_n(c.v); put_c(' ');
+ int** list = new(int*, 2);
+ int* item = new(int);
+ *item = 8;
+ list[1] = item;
+ int* e = list[1];
+ put_n(*e); put_c(10);
+ free(d*p); free(d*a); free(d*list);
+ return 0;
+}