• SavvyWolf@pawb.social
    link
    fedilink
    English
    arrow-up
    59
    arrow-down
    1
    ·
    3 days ago

    You actually shouldn’t do this!

    This doesn’t introduce a new scope, so accidentally using x outside of the case block is UB. Instead you should introduce a new scope like so:

    switch (foo)  {
      case BAZ: {
        int x = ...;
        foobar(x);
      }
    }