OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [lcc/] [tst/] [switch.c] - Blame information for rev 243

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 hellwig
main()
2
{
3
        int i; char *s;
4
 
5
        for (s = "bfnrtvx"; *s; s++)
6
                printf("%c = 0x%x\n", *s, backslash(*s));
7
        f();
8
        g();
9
        h();
10
        for (i = 0x1000000; i&0x7000000; i += 0x1000000)
11
                big(i);
12
        limit();
13
        return 0;
14
}
15
 
16
backslash(c)
17
{
18
        switch (c) {
19
        case 'b':
20
                return '\b';
21
        case 'f':
22
                return '\f';
23
        case 'n':
24
                return '\n';
25
        case 'r':
26
                return '\r';
27
        case 't':
28
                return '\t';
29
        case 'v':
30
                return '\v';
31
        }
32
        return c;
33
}
34
 
35
f() {
36
        int i, x = 0, y;
37
 
38
        printf("f:\n");
39
        for (i = 0; i <= 20; i++) {
40
                y = i;
41
                switch (i) {
42
                case 1: x = i; break;
43
                case 2: x = i; break;
44
                case 7: x = i; break;
45
                case 8: x = i; break;
46
                case 9: x = i; break;
47
                case 16: x = i; break;
48
                case 17: x = i; break;
49
                case 18: x = i; break;
50
                case 19: x = i; break;
51
                case 20: x = i; break;
52
                }
53
                printf("x = %d\n", x);
54
        }
55
}
56
 
57
g() {
58
        int i;
59
 
60
        printf("g:\n");
61
        for (i = 1; i <= 10; i++)
62
                switch (i) {
63
                case 1: case 2: printf("1 %d\n", i); break;
64
                case 3: case 4: case 5: printf("2 %d\n", i); break;
65
                case 6: case 7: case 8: printf("3 %d\n", i);
66
                default:
67
                        printf("d %d\n", i); break;
68
                case 1001: case 1002: case 1003: case 1004:
69
                        printf("5 %d\n", i); break;
70
                case 3001: case 3002: case 3003: case 3004:
71
                        printf("6 %d\n", i); break;
72
        }
73
}
74
 
75
h()
76
{
77
        int i, n=0;
78
 
79
        printf("h:\n");
80
        for (i = 1; i <= 500; i++)
81
                switch (i) {
82
                default: n++; continue;
83
                case 128: printf("i = %d\n", i); break;
84
                case 16: printf("i = %d\n", i); break;
85
                case 8: printf("i = %d\n", i); break;
86
                case 120: printf("i = %d\n", i); break;
87
                case 280: printf("i = %d\n", i); break;
88
                case 264: printf("i = %d\n", i); break;
89
                case 248: printf("i = %d\n", i); break;
90
                case 272: printf("i = %d\n", i); break;
91
                case 304: printf("i = %d\n", i); break;
92
                case 296: printf("i = %d\n", i); break;
93
                case 288: printf("i = %d\n", i); break;
94
                case 312: printf("i = %d\n", i); break;
95
                }
96
        printf("%d defaults\n", n);
97
}
98
 
99
big(x) unsigned x; {
100
        switch(x&0x6000000){
101
        case -1:
102
        case -2:
103
        case 0x0000000:
104
                printf("x = 0x%x\n", x); break;
105
        case 0x2000000:
106
                printf("x = 0x%x\n", x); break;
107
        case 0x4000000:
108
                printf("x = 0x%x\n", x); break;
109
        default:
110
                printf("x = 0x%x (default)\n", x); break;
111
        }
112
}
113
 
114
#include <limits.h>
115
 
116
limit() {
117
        int i;
118
 
119
        for (i = INT_MIN; i <= INT_MIN+5; i++)
120
                switch (i) {
121
                case INT_MIN:   printf("0\n"); break;
122
                case INT_MIN+1: printf("1\n"); break;
123
                case INT_MIN+2: printf("2\n"); break;
124
                case INT_MIN+3: printf("3\n"); break;
125
                case INT_MIN+4: printf("4\n"); break;
126
                default:        printf("5\n"); break;
127
                }
128
        for (i = INT_MAX; i >= INT_MAX-5; i--)
129
                switch (i) {
130
                case INT_MAX:   printf("0\n"); break;
131
                case INT_MAX-1: printf("1\n"); break;
132
                case INT_MAX-2: printf("2\n"); break;
133
                case INT_MAX-3: printf("3\n"); break;
134
                case INT_MAX-4: printf("4\n"); break;
135
                default:        printf("5\n"); break;
136
                }
137
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.