aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/alias.zc
diff options
context:
space:
mode:
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;
+}