forked from rui314/chibicc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sizeof.c
105 lines (87 loc) · 2.78 KB
/
sizeof.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "test.h"
int main() {
ASSERT(1, sizeof(char));
ASSERT(2, sizeof(short));
ASSERT(2, sizeof(short int));
ASSERT(2, sizeof(int short));
ASSERT(4, sizeof(int));
ASSERT(8, sizeof(long));
ASSERT(8, sizeof(long int));
ASSERT(8, sizeof(long int));
ASSERT(8, sizeof(char *));
ASSERT(8, sizeof(int *));
ASSERT(8, sizeof(long *));
ASSERT(8, sizeof(int **));
ASSERT(8, sizeof(int(*)[4]));
ASSERT(32, sizeof(int*[4]));
ASSERT(16, sizeof(int[4]));
ASSERT(48, sizeof(int[3][4]));
ASSERT(8, sizeof(struct {int a; int b;}));
ASSERT(8, sizeof(-10 + (long)5));
ASSERT(8, sizeof(-10 - (long)5));
ASSERT(8, sizeof(-10 * (long)5));
ASSERT(8, sizeof(-10 / (long)5));
ASSERT(8, sizeof((long)-10 + 5));
ASSERT(8, sizeof((long)-10 - 5));
ASSERT(8, sizeof((long)-10 * 5));
ASSERT(8, sizeof((long)-10 / 5));
ASSERT(1, ({ char i; sizeof(++i); }));
ASSERT(1, ({ char i; sizeof(i++); }));
ASSERT(8, sizeof(int(*)[10]));
ASSERT(8, sizeof(int(*)[][10]));
ASSERT(4, sizeof(struct { int x, y[]; }));
ASSERT(1, sizeof(char));
ASSERT(1, sizeof(signed char));
ASSERT(1, sizeof(signed char signed));
ASSERT(1, sizeof(unsigned char));
ASSERT(1, sizeof(unsigned char unsigned));
ASSERT(2, sizeof(short));
ASSERT(2, sizeof(int short));
ASSERT(2, sizeof(short int));
ASSERT(2, sizeof(signed short));
ASSERT(2, sizeof(int short signed));
ASSERT(2, sizeof(unsigned short));
ASSERT(2, sizeof(int short unsigned));
ASSERT(4, sizeof(int));
ASSERT(4, sizeof(signed int));
ASSERT(4, sizeof(signed));
ASSERT(4, sizeof(signed signed));
ASSERT(4, sizeof(unsigned int));
ASSERT(4, sizeof(unsigned));
ASSERT(4, sizeof(unsigned unsigned));
ASSERT(8, sizeof(long));
ASSERT(8, sizeof(signed long));
ASSERT(8, sizeof(signed long int));
ASSERT(8, sizeof(unsigned long));
ASSERT(8, sizeof(unsigned long int));
ASSERT(8, sizeof(long long));
ASSERT(8, sizeof(signed long long));
ASSERT(8, sizeof(signed long long int));
ASSERT(8, sizeof(unsigned long long));
ASSERT(8, sizeof(unsigned long long int));
ASSERT(1, sizeof((char)1));
ASSERT(2, sizeof((short)1));
ASSERT(4, sizeof((int)1));
ASSERT(8, sizeof((long)1));
ASSERT(4, sizeof((char)1 + (char)1));
ASSERT(4, sizeof((short)1 + (short)1));
ASSERT(4, sizeof(1?2:3));
ASSERT(4, sizeof(1?(short)2:(char)3));
ASSERT(8, sizeof(1?(long)2:(char)3));
ASSERT(1, sizeof(char) << 31 >> 31);
ASSERT(1, sizeof(char) << 63 >> 63);
ASSERT(4, sizeof(float));
ASSERT(8, sizeof(double));
ASSERT(4, sizeof(1f+2));
ASSERT(8, sizeof(1.0+2));
ASSERT(4, sizeof(1f-2));
ASSERT(8, sizeof(1.0-2));
ASSERT(4, sizeof(1f*2));
ASSERT(8, sizeof(1.0*2));
ASSERT(4, sizeof(1f/2));
ASSERT(8, sizeof(1.0/2));
ASSERT(16, sizeof(long double));
ASSERT(1, sizeof(main));
printf("OK\n");
return 0;
}