aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/alias.zc
blob: 2ebc3e51314c2021580fae49b27cce80cc668974 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}