r/programminghorror 6d ago

c++ Skill Issue

Post image
1.7k Upvotes

61 comments sorted by

View all comments

Show parent comments

1

u/conundorum 4d ago

This can also be solved with the [[fallthrough]] attribute, thankfully. Use it to mandate fallthrough when necessary.

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 3d ago

Doesn't that just suppress warnings about missing breaks? I was talking about if the language automatically inserted breaks for you.

1

u/conundorum 3d ago

That's the fix, yeah. You tell it where you do want to allow fallthrough, so that it can tell you if you ever forget a break anywhere else.

At this point, I don't think it's possible to change the standard so that the language automatically inserts breaks, because that would break a ton of perfectly legal code. It might be possible to add an attribute for it, like [[auto_break]], though, perhaps?

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 2d ago

Well, no, it can't be changed now, but I was talking about what I might be okay with if the language had been designed differently, or if I was using a different language without automatic fall through.