• SavvyWolf@pawb.social
    link
    fedilink
    English
    arrow-up
    0
    ·
    20 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);
      }
    }