Switch statement overkill?
1
Name:
Anonymous
2011-06-27 18:27
I know a guy that says you should replace every conditional with a switch.
2
Name:
Anonymous
2011-06-27 18:28
I know a guy that rubs peanut butter on his scrotum and then lets his dog lick it off.
3
Name:
Anonymous
2011-06-27 18:31
I'm the guy
>>2 knows and I strongly disagree with the guy
>>1 knows.
4
Name:
Anonymous
2011-06-27 18:36
OP here,
He replacing every if-else in his C programs with switch, even nested switches!
5
Name:
Anonymous
2011-06-27 18:53
Well, if he uses fall-throughs it might be a good idea. Otherwise, no.
6
Name:
Anonymous
2011-06-27 22:54
I know a guy that says you should replace every switch with a vtable
7
Name:
Anonymous
2011-06-27 23:03
8
Name:
Anonymous
2011-06-27 23:11
I know a guy that says you should replace every switch with a case
9
Name:
Anonymous
2011-06-27 23:18
I know a guy that says he is gonna replace every scientist with an artist
10
Name:
Anonymous
2011-06-28 0:45
int x = 1;
switch(x==1){
case 0: printf("false"); break;
default: printf("true");
}
11
Name:
Anonymous
2011-06-28 1:23
<-- dubz, check'em
12
Name:
Anonymous
2011-06-28 2:29
Zwölf.
13
Name:
Anonymous
2011-06-28 3:35
I know a guy that says you should unroll every loop with Duff's Device.
void copy(int *to, int *from, size_t count) {
size_t n = (count + 7) >> 3;
switch (count & 7) {
case 0: do { *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while (--n > 0);
}
}
14
Name:
Anonymous
2011-06-28 3:56
"GRUNNUR"
15
Name:
Anonymous
2011-06-28 4:44
I know a guy
16
Name:
Anonymous
2011-06-28 7:51
decent benchmarks or gtfo
17
Name:
Anonymous
2011-06-28 11:51
>2011
>Not using hashmaps with function pointers
18
Name:
Anonymous
2011-06-28 14:00
I am a guy who knows that switch and if else are treated the same by the compiler, so do whatever gives you more of a boner.
19
Name:
Anonymous
2011-06-28 14:41
20
Name:
Anonymous
2011-06-28 15:21
i know no one cose im a autist :(
21
Name:
Anonymous
2011-06-28 15:27
switch (x) {
case -1:
case -2:
case -3:
case -4
case -5
case -6
case -7
case -8:
case -9:
case -10:
case -11:
case -12: //lol i bet it can't be less than this
result = 0
break;
default:
result = sqrt(x);
}
versus
if (x < 0)
result = 0;
else
result = sqrt(x);
Of course I like the switch-case version more.
22
Name:
>>10
2011-06-28 16:07
>>21
switch(x < 0){
case 0: result = sqrt(x); break;
default: result = 0;
}
23
Name:
Anonymous
2011-06-28 19:30
__assume(0); in MSVC will get you a fast, unchecked table jump
Intel C++ compiler often statically infer whether the default: case happen or not.
24
Name:
Anonymous
2011-06-28 19:41
25
Name:
Anonymous
2011-06-29 10:33
>>22
#include <stdbool.h>
switch(x < 0)
{
case false:
result = 0;
break;
default:
result = sqrt(x);
break;
}
Newer Posts