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