2017-03-10 10:21:14 +00:00
|
|
|
/*
|
|
|
|
!!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);
|
2017-03-10 10:21:14 +00:00
|
|
|
|
2019-02-12 21:50:49 +00:00
|
|
|
switch(i) {
|
|
|
|
case -1: /* works */
|
|
|
|
/* case 0xffff: */ /* 'range error' (-1) */
|
2017-03-10 10:21:14 +00:00
|
|
|
|
2019-02-12 21:50:49 +00:00
|
|
|
printf("-1\n");
|
|
|
|
break;
|
|
|
|
/* max int */
|
2017-03-10 10:21:14 +00:00
|
|
|
|
2019-02-12 21:50:49 +00:00
|
|
|
/* case 0x7fff: */ /* works */
|
|
|
|
case 32767: /* works */
|
|
|
|
/* case 32768: */ /* 'range error' (correct for that one!) */
|
2017-03-10 10:21:14 +00:00
|
|
|
|
2019-02-12 21:50:49 +00:00
|
|
|
printf("max\n");
|
|
|
|
break;
|
|
|
|
/* min int */
|
2017-03-10 10:21:14 +00:00
|
|
|
|
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");
|
2017-03-10 10:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testdefault1(unsigned char i) {
|
|
|
|
|
2020-06-25 06:54:58 +00:00
|
|
|
signed char k;
|
2017-03-10 10:21:14 +00:00
|
|
|
|
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 */
|
2017-03-10 10:21:14 +00:00
|
|
|
|
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; */
|
|
|
|
}
|
|
|
|
}
|
2017-03-10 10:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testdefault2(unsigned char i) {
|
|
|
|
|
2020-06-25 06:54:58 +00:00
|
|
|
unsigned char k;
|
2017-03-10 10:21:14 +00:00
|
|
|
|
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 ? */
|
2017-03-10 10:21:14 +00:00
|
|
|
|
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; */
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
testdefault1(1);
|
|
|
|
testdefault1(2);
|
|
|
|
testdefault1(3);
|
|
|
|
testdefault1(4);
|
|
|
|
|
|
|
|
testdefault2(1);
|
|
|
|
testdefault2(2);
|
|
|
|
testdefault2(3);
|
|
|
|
testdefault2(4);
|
2017-03-10 10:21:14 +00:00
|
|
|
|
2019-02-12 21:50:49 +00:00
|
|
|
return 0;
|
2017-03-10 10:21:14 +00:00
|
|
|
}
|