you are viewing a single comment's thread
view the rest of the comments
[–] 58 points 6 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);
  }
}
  • source