forked from rui314/chibicc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cast.c
59 lines (51 loc) · 1.63 KB
/
cast.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
#include "test.h"
int main() {
ASSERT(131585, (int)8590066177);
ASSERT(513, (short)8590066177);
ASSERT(1, (char)8590066177);
ASSERT(1, (long)1);
ASSERT(0, (long)&*(int *)0);
ASSERT(513, ({ int x=512; *(char *)&x=1; x; }));
ASSERT(5, ({ int x=5; long y=(long)&x; *(int*)y; }));
(void)1;
ASSERT(-1, (char)255);
ASSERT(-1, (signed char)255);
ASSERT(255, (unsigned char)255);
ASSERT(-1, (short)65535);
ASSERT(65535, (unsigned short)65535);
ASSERT(-1, (int)0xffffffff);
ASSERT(0xffffffff, (unsigned)0xffffffff);
ASSERT(1, -1<1);
ASSERT(0, -1<(unsigned)1);
ASSERT(254, (char)127+(char)127);
ASSERT(65534, (short)32767+(short)32767);
ASSERT(-1, -1>>1);
ASSERT(-1, (unsigned long)-1);
ASSERT(2147483647, ((unsigned)-1)>>1);
ASSERT(-50, (-100)/2);
ASSERT(2147483598, ((unsigned)-100)/2);
ASSERT(9223372036854775758, ((unsigned long)-100)/2);
ASSERT(0, ((long)-1)/(unsigned)100);
ASSERT(-2, (-100)%7);
ASSERT(2, ((unsigned)-100)%7);
ASSERT(6, ((unsigned long)-100)%9);
ASSERT(65535, (int)(unsigned short)65535);
ASSERT(65535, ({ unsigned short x = 65535; x; }));
ASSERT(65535, ({ unsigned short x = 65535; (int)x; }));
ASSERT(-1, ({ typedef short T; T x = 65535; (int)x; }));
ASSERT(65535, ({ typedef unsigned short T; T x = 65535; (int)x; }));
ASSERT(0, (_Bool)0.0);
ASSERT(1, (_Bool)0.1);
ASSERT(3, (char)3.0);
ASSERT(1000, (short)1000.3);
ASSERT(3, (int)3.99);
ASSERT(2000000000000000, (long)2e15);
ASSERT(3, (float)3.5);
ASSERT(5, (double)(float)5.5);
ASSERT(3, (float)3);
ASSERT(3, (double)3);
ASSERT(3, (float)3L);
ASSERT(3, (double)3L);
printf("OK\n");
return 0;
}