about summary refs log tree commit diff
path: root/examples/18.src
blob: 741a460f57be8cefa71d1c0145d9266fd10c6a2c (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
24
25
26
27
28
29
30
extern malloc = (i64) => *void;
extern free = (*void) => void;

import "!stdlib.src";

let main = () => i64 {
	let x = cast(*i8, malloc(24));
	(*(x+cast(*i8, 0))) = 10;
	(*(x+cast(*i8, 1))) = 20;
	(*(x+cast(*i8, 2))) = 40;
	printf("%p\n", x);
	printf("%d\n", *(x+cast(*i8, 0)));
	printf("%d\n", *(x+cast(*i8, 1)));
	printf("%d\n", *(x+cast(*i8, 2)));
	free(cast(*void, x));
	return 0;
};

/*

Expected stdout:

${SOMEPOINTER}
10
20
40

Expected return: 0

*/