aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/arrays.zc
blob: a8a12bfcf92c282d6a235dbe9d8c1c1de7185cc4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 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);
		put_n(len(a)); put_c(' '); put_n(cap(a)); put_c(' '); put_n(a[99]); put_c(' ');
		put_n(pop(a)); put_c(' '); put_n(len(a)); put_c(' ');
		resize(a, 3); put_n(len(a)); put_c(' '); put_n(a[2]); put_c(' ');
		fixed []int f = new(fixed []int, 5);
		f[4] = 7; put_n(f[4] + len(f)); put_c(' ');
		[]point ps = new([]point, 2);
		ps[1].y = 9; resize(ps, 10); put_n(ps[1].y + len(ps)); put_c(' ');
		[8]int st; put_n(len(st)); put_c(' ');
		[]point* owned = new([]point*);
		for (int i = 0; i < 20; i++) { point* p = new(point); p.x = i; push(owned, d*p); }
		put_n(owned[19].x); put_c(' ');
		put_n(live_objects() - before); put_c(10);
	}
	put_n(live_objects() - before); put_c(10);
	return 0;
}