Name: Anonymous 2011-06-27 18:27
I know a guy that says you should replace every conditional with a switch.
switch with a case
int x = 1;
switch(x==1){
case 0: printf("false"); break;
default: printf("true");
}
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);
}
}
"GRUNNUR"
switch and if else are treated the same by the compiler, so do whatever gives you more of a boner.
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);
}
if (x < 0)
result = 0;
else
result = sqrt(x);
#include <stdbool.h>
switch(x < 0)
{
case false:
result = 0;
break;
default:
result = sqrt(x);
break;
}