0189-cpp.c - scc - simple c99 compiler
(HTM) git clone git://git.simple-cc.org/scc
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
0189-cpp.c (1167B)
---
1 /* taken from ISO/IEC 9899:1999 Section 6.10.3.5 p5 */
2
3 int z[3] = {1, 0, 0};
4
5 int
6 f(int x)
7 {
8 return x+1;
9 }
10
11 int
12 t(int x)
13 {
14 return x+2;
15 }
16
17 int
18 m(int x, int y)
19 {
20 return x+y;
21 }
22
23 #define x 3
24 #define f(a) f(x * (a))
25 #undef x
26
27 #define x 2
28 #define z z[0]
29 #define g f
30 #define h g(~
31 #define m(a) a(w)
32 #define w 0,1
33 #define t(a) a
34 #define p() int
35 #define q(x) x
36 #define r(x,y) x ## y
37 #define str(x) # x
38
39 int
40 test1()
41 {
42 return f(z) == 3;
43 }
44
45 int
46 test2(int y)
47 {
48 return f(y+1) + f(f(z)) % t(t(g)(0) + t)(1) == 10;
49 }
50
51 int
52 test3()
53 {
54 return g(x+(3,4)-w) | h 5) & m
55 (f)^m(m) == 3;
56 }
57
58 int
59 test4()
60 {
61 p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
62
63 return i[0] + i[1] + i[2] + i[3] == 33;
64 }
65
66 int
67 test5()
68 {
69 int i;
70 char c[2][6] = { str(hello), str() };
71
72 for (i = 0; i < 6; i++) {
73 if (c[0][i] != "hello"[i])
74 return 0;
75 }
76
77 if (c[1][0] != '\0')
78 return 0;
79
80 return 1;
81 }
82
83 int
84 main()
85 {
86 if (!test1())
87 return 1;
88 if (!test2(2))
89 return 2;
90 if (!test3())
91 return 3;
92 if (!test4())
93 return 4;
94 if (!test5())
95 return 5;
96 return 0;
97 }