summaryrefslogtreecommitdiff
path: root/tests/ptr_arithmetic.toc
blob: 05975e8a00875cc282cae335e5c5b2eb2894f910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "std/io.toc";
#include "std/mem.toc";

ptr_arithmetic_test ::= fn() total := 0 {
	foo := news(int, 10);
	for p, i := &foo {
		*p = i;
	}
	p := &foo[0];
	
	p += 2;
	total += *p;
	total += *(p + 3);
	total += *(p - 1);

	voidp : &void = &foo[7];
	total += *(voidp as &int);
	voidp = voidp + 8;
	total += *(voidp as &int);
	voidp += 8;
	total += *(voidp as &int);
	voidp = voidp - 8;
	total += *(voidp as &int);
	voidp -= 8;
	total += *(voidp as &int);
}

main ::= fn() {
	x ::= ptr_arithmetic_test();
	y := ptr_arithmetic_test();
	puti(x);
	puti(y);
}