139
you are viewing a single comment's thread
view the rest of the comments
[-] savvywolf@pawb.social 57 points 2 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);
  }
}
this post was submitted on 21 Sep 2026
139 points (99.3% liked)

Programmer Humor

33314 readers
860 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS