]> git.sur5r.net Git - cc65/blob - test/ref/switch2.c
Merge pull request #135 from ikorb/patch1
[cc65] / test / ref / switch2.c
1 /*\r
2   !!DESCRIPTION!! switch test\r
3   !!ORIGIN!!\r
4   !!LICENCE!!     public domain\r
5 */\r
6 \r
7 /*#define STANDALONE*/\r
8 \r
9 #include <stdio.h>\r
10 \r
11 void testlimits(int i) {
12         printf("%d:",i);\r
13 \r
14         switch(i) {
15                 case -1:        /* works */\r
16                 /* case 0xffff: */ /* 'range error' (-1) */\r
17 \r
18                         printf("-1\n");\r
19                         break;\r
20                 /* max int */\r
21 \r
22 /*               case 0x7fff:   */         /* works */\r
23                 case 32767:                /* works */\r
24                 /* case 32768: */          /* 'range error' (correct for that one!) */\r
25 \r
26                         printf("max\n");\r
27                         break;\r
28                 /* min int */\r
29 \r
30                 case -32768:               /* 'warning. constant is long' */\r
31                 /* case 0x8000: */             /* 'range error' */\r
32                 /* case -32769: */         /* 'range error' (correct for that one!) */\r
33                         printf("min\n");\r
34                         break;\r
35         }\r
36         printf("\n");\r
37 }\r
38 \r
39 void testdefault1(unsigned char i) {\r
40 /* we want a signed char */\r
41 #ifdef REFCC\r
42 \r
43 #ifdef REFCC_UNSIGNED_CHARS\r
44 signed char k;\r
45 #else\r
46 char k;\r
47 #endif\r
48         \r
49 #else\r
50         \r
51 #ifdef UNSIGNED_CHARS\r
52 signed char k;\r
53 #else\r
54 char k;\r
55 #endif\r
56 \r
57 #endif\r
58 \r
59         for(;i<254;) {\r
60                 k = i;\r
61                 printf(">%d\n",i);i++;\r
62                 switch(k) {\r
63                 case 1:\r
64                         break;\r
65                 case 2:\r
66                         break;\r
67                 case 3:\r
68                         break;\r
69                 case 4:\r
70                         break;\r
71                 case 5:\r
72                         break;\r
73                 case 6:\r
74                         break;\r
75                 case 7:\r
76                         break;\r
77                 case 8:\r
78                         break;\r
79                 case 9:\r
80                         break;\r
81                 case 10:\r
82                         break;\r
83                 case 11:\r
84                         break;\r
85                 case 12:\r
86                         break;\r
87                 case 13:\r
88                         break;\r
89                 case 14:\r
90                         break;\r
91                 case 15:\r
92                         break;\r
93                 case 17:\r
94                         break;\r
95                 /* triggers bug ? */\r
96                 /* gcc warning: case label value exceeds maximum value for type */\r
97                 /* cc65 error: range error */\r
98 \r
99                 /*\r
100                 case 170:\r
101                         break;\r
102                 */\r
103                 case 18:\r
104                         break;\r
105                 case 19:\r
106                         break;\r
107                 case 20:\r
108                         break;\r
109                 case 21:\r
110                         break;\r
111                 case 22:\r
112                         break;\r
113                 case 23:\r
114                         break;\r
115                 case 24:\r
116                         switch(k) {\r
117                                 case 1:\r
118                                         break;\r
119                                 case 2:\r
120                                         break;\r
121                                 case 3:\r
122                                         break;\r
123                                 case 4:\r
124                                 case 5:\r
125                                 break;\r
126                                 case 6:\r
127                                 case 7:\r
128                                         break;\r
129                                 case 8:\r
130                                 case 9:\r
131                                         break;\r
132                                 }\r
133                         break;\r
134                 case 100:\r
135                         break;\r
136                 default:\r
137                         printf(">>>default\n");\r
138                         /* triggers bug if this break; is missing? */\r
139                         /* break; */\r
140                 }\r
141         }\r
142 }\r
143 \r
144 void testdefault2(unsigned char i) {\r
145 /* we want a unsigned char */\r
146 #ifdef REFCC\r
147 \r
148 #ifdef REFCC_UNSIGNED_CHARS\r
149 char k;\r
150 #else\r
151 unsigned char k;\r
152 #endif\r
153         \r
154 #else\r
155         \r
156 #ifdef UNSIGNED_CHARS\r
157 char k;\r
158 #else\r
159 unsigned char k;\r
160 #endif\r
161 \r
162 #endif\r
163 \r
164         for(;i<254;) {\r
165                 k = i;\r
166                 printf(">%d\n",i);i++;\r
167                 switch(k) {\r
168                 case 1:\r
169                         break;\r
170                 case 2:\r
171                         break;\r
172                 case 3:\r
173                         break;\r
174                 case 4:\r
175                         break;\r
176                 case 5:\r
177                         break;\r
178                 case 6:\r
179                         break;\r
180                 case 7:\r
181                         break;\r
182                 case 8:\r
183                         break;\r
184                 case 9:\r
185                         break;\r
186                 case 10:\r
187                         break;\r
188                 case 11:\r
189                         break;\r
190                 case 12:\r
191                         break;\r
192                 case 13:\r
193                         break;\r
194                 case 14:\r
195                         break;\r
196                 case 15:\r
197                         break;\r
198                 case 17:\r
199                         break;\r
200                 /* triggers bug ? */\r
201 \r
202                 case 170:\r
203                         break;\r
204                 \r
205                 case 18:\r
206                         break;\r
207                 case 19:\r
208                         break;\r
209                 case 20:\r
210                         break;\r
211                 case 21:\r
212                         break;\r
213                 case 22:\r
214                         break;\r
215                 case 23:\r
216                         break;\r
217                 case 24:\r
218                         switch(k) {\r
219                                 case 1:\r
220                                         break;\r
221                                 case 2:\r
222                                         break;\r
223                                 case 3:\r
224                                         break;\r
225                                 case 4:\r
226                                 case 5:\r
227                                 break;\r
228                                 case 6:\r
229                                 case 7:\r
230                                         break;\r
231                                 case 8:\r
232                                 case 9:\r
233                                         break;\r
234                                 }\r
235                         break;\r
236                 case 100:\r
237                         break;\r
238                 default:\r
239                         printf(">>>default\n");\r
240                         /* triggers bug if this break; is missing? */\r
241                         /* break; */\r
242                 }\r
243         }\r
244 }
245
246 int main(void) {
247         testlimits(32767);\r
248         testlimits(-32768);\r
249         testlimits(-1);\r
250         \r
251         testdefault1(1);\r
252         testdefault1(2);\r
253         testdefault1(3);\r
254         testdefault1(4);\r
255         \r
256         testdefault2(1);\r
257         testdefault2(2);\r
258         testdefault2(3);\r
259         testdefault2(4);\r
260 \r
261         return 0;\r
262 }\r