1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-19 21:32:19 +00:00
cc65/test/ref/switch2.c

231 lines
6.4 KiB
C
Raw Normal View History

/*
!!DESCRIPTION!! switch test
!!ORIGIN!!
!!LICENCE!! public domain
*/
/*#define STANDALONE*/
#include <stdio.h>
2014-09-24 14:45:10 +00:00
void testlimits(int i) {
2019-02-12 21:50:49 +00:00
printf("%d:",i);
2019-02-12 21:50:49 +00:00
switch(i) {
case -1: /* works */
/* case 0xffff: */ /* 'range error' (-1) */
2019-02-12 21:50:49 +00:00
printf("-1\n");
break;
/* max int */
2019-02-12 21:50:49 +00:00
/* case 0x7fff: */ /* works */
case 32767: /* works */
/* case 32768: */ /* 'range error' (correct for that one!) */
2019-02-12 21:50:49 +00:00
printf("max\n");
break;
/* min int */
2019-02-12 21:50:49 +00:00
case -32768: /* 'warning. constant is long' */
/* case 0x8000: */ /* 'range error' */
/* case -32769: */ /* 'range error' (correct for that one!) */
printf("min\n");
break;
}
printf("\n");
}
void testdefault1(unsigned char i) {
signed char k;
2019-02-12 21:50:49 +00:00
for(;i<254;) {
k = i;
printf(">%d\n",i);i++;
switch(k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
break;
case 12:
break;
case 13:
break;
case 14:
break;
case 15:
break;
case 17:
break;
/* triggers bug ? */
/* gcc warning: case label value exceeds maximum value for type */
/* cc65 error: range error */
2019-02-12 21:50:49 +00:00
/*
case 170:
break;
*/
case 18:
break;
case 19:
break;
case 20:
break;
case 21:
break;
case 22:
break;
case 23:
break;
case 24:
switch(k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
case 5:
break;
case 6:
case 7:
break;
case 8:
case 9:
break;
}
break;
case 100:
break;
default:
printf(">>>default\n");
/* triggers bug if this break; is missing? */
/* break; */
}
}
}
void testdefault2(unsigned char i) {
unsigned char k;
2019-02-12 21:50:49 +00:00
for(;i<254;) {
k = i;
printf(">%d\n",i);i++;
switch(k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
break;
case 12:
break;
case 13:
break;
case 14:
break;
case 15:
break;
case 17:
break;
/* triggers bug ? */
2019-02-12 21:50:49 +00:00
case 170:
break;
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
case 18:
break;
case 19:
break;
case 20:
break;
case 21:
break;
case 22:
break;
case 23:
break;
case 24:
switch(k) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
case 5:
break;
case 6:
case 7:
break;
case 8:
case 9:
break;
}
break;
case 100:
break;
default:
printf(">>>default\n");
/* triggers bug if this break; is missing? */
/* break; */
}
}
2014-09-24 14:45:10 +00:00
}
int main(void) {
2019-02-12 21:50:49 +00:00
testlimits(32767);
testlimits(-32768);
testlimits(-1);
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
testdefault1(1);
testdefault1(2);
testdefault1(3);
testdefault1(4);
2022-04-17 14:07:52 +00:00
2019-02-12 21:50:49 +00:00
testdefault2(1);
testdefault2(2);
testdefault2(3);
testdefault2(4);
2019-02-12 21:50:49 +00:00
return 0;
}