Suppose I have a variable, int x
, deciding in a switch/case
, and I want two possible actions: one for x=1, x=2, x=5
and another for x=3, x=4
. Is the following code acceptable in terms of codiquette?
switch (x)
{
case 1:
case 2:
default:
// do something
case 3:
case 4:
// do something else
}
I realize it also works for x>5
, but that's not a problem in my case, and it seems to work, gcc 6.1.1, archlinux 64. The reason is that do something
involves calling a not-so-small function and I'd like to avoid writing it twice (code bloating?), even if it's just a matter of copy-paste.