summaryrefslogtreecommitdiff
path: root/test/align.myr
blob: a103817c5963bb1cb19d4c7df3251c7a9deaa6b5 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std

/* size should be 1 */
type alignstruct0 = struct
	a : byte
;;

/* size should be 16 */
type alignstruct1 = struct
	a : byte
	b : byte[15]
;;

/* size should be 20 */
type alignstruct2 = struct
	a : int
	b : byte[15]
	/* 1 byte padding */
;;

/* size should be 20 */
type alignstruct3 = struct
	b : byte[15]
	a : int
;;

/* size should be 8 */
type alignstruct4 = struct
	a : byte
	b : int[1]
;;

/* size should be 24 */
type alignstruct5 = struct
	a : byte
	b : byte[:]
;;

/* size should be 8 */
type alignstruct6 = struct
	a : byte
	b : byte
	c : byte
	d : byte
	e : int32
;;

/* size should be 24 */
type alignstruct7 = struct
	a : byte
	b : int32
	c : byte[:]
;;

const main = {
	std.put("size = {}\n", sizeof(alignstruct0))
	std.put("size = {}\n", sizeof(alignstruct1))
	std.put("size = {}\n", sizeof(alignstruct2))
	std.put("size = {}\n", sizeof(alignstruct3))
	std.put("size = {}\n", sizeof(alignstruct4))
	std.put("size = {}\n", sizeof(alignstruct5))
	std.put("size = {}\n", sizeof(alignstruct6))
	std.put("size = {}\n", sizeof(alignstruct7))
	/* size should be 8 */
	std.put("size = {}\n", sizeof((int, byte, byte)))
	/* size should be 16 */
	std.put("size = {}\n", sizeof((int, byte, int, byte)))
	/* size should be 12 */
	std.put("size = {}\n", sizeof((int, int, byte, byte)))
}