boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

106-switch-fallthrough.c (626B)


      1 /* Switch with explicit fallthrough (no break) and default not last. */
      2 
      3 int classify(int x) {
      4     int r = 0;
      5     switch (x) {
      6         case 1: r = r + 1;     /* fallthrough */
      7         case 2: r = r + 10;    /* fallthrough */
      8         case 3: r = r + 100; break;
      9         default: r = -1; break;
     10         case 4: r = r + 1000; break;
     11     }
     12     return r;
     13 }
     14 
     15 int main(int argc, char **argv) {
     16     if (classify(1) != 111) return 1;   /* 1+10+100 */
     17     if (classify(2) != 110) return 2;   /* 10+100 */
     18     if (classify(3) != 100) return 3;
     19     if (classify(4) != 1000) return 4;
     20     if (classify(5) != -1)  return 5;
     21     return 0;
     22 }