From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- tests/programs/alias.zc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/programs/alias.zc (limited to 'tests/programs/alias.zc') 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; +} -- cgit v1.2.3