switch_test.c 690 Bytes
Newer Older
Matthias Braun's avatar
Matthias Braun committed
1
int test(int a)
Christian Würdig's avatar
Christian Würdig committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
  int b = 0xff;

  switch (a * b) {
    case 0:
      b *= a;
    case 1:
      b *= a;
      ++b;
      break;
    case 2:
      b /= a;
      break;
    case 3:
      b *= a*a;
      break;
    case 4:
      b = a % 3;
      break;
    case 5:
      b = 2;
      break;
    default:
      return 0;
  }
  return b;
}

int main()
{
  printf("SwitchTest\n");
  printf(" on %d %d\n", -1, test(-1));
  printf(" on %d %d\n", 0, test(0));
  printf(" on %d %d\n", 1, test(1));
  printf(" on %d %d\n", 2, test(2));
  printf(" on %d %d\n", 3, test(3));
  printf(" on %d %d\n", 4, test(4));
  printf(" on %d %d\n", 5, test(5));
  printf(" on %d %d\n", 6, test(6));
Matthias Braun's avatar
Matthias Braun committed
41
42

  return 0;
Christian Würdig's avatar
Christian Würdig committed
43
}