File: fallthrough.c

package info (click to toggle)
chibicc 1.0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,832 kB
  • sloc: ansic: 62,911; sh: 275; makefile: 92
file content (31 lines) | stat: -rw-r--r-- 583 bytes parent folder | download
1
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
#include "test.h"

int main() {
  int state = 0;
  int c = '5'; // ASCII value of character '5'
  int arg = -1;

  switch (state) {
    case 0:
      // Simulate condition that fails (c < 0x3c or c > 0x3f), so no break
      if (c >= 0x3c && c <= 0x3f) {
        // shouldn't enter here
        break;
      }

      // fallthrough to case 1
      arg = 0;
      // no break

    case 1:
      if (c >= '0' && c <= '9') {
        arg *= 10;
        arg += c - '0';
      }
      break;
  }

  printf("arg = %d\n", arg);
  ASSERT(5, arg);
  return 0;
}