Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Switch statement overkill?

Name: Anonymous 2011-06-27 18:27

I know a guy that says you should replace every conditional with a switch.

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.

Name: Anonymous 2011-06-27 18:31

I'm the guy >>2 knows and I strongly disagree with the guy >>1 knows.

Name: Anonymous 2011-06-27 18:36

OP here,
He replacing every if-else in his C programs with switch, even nested switches!

Name: Anonymous 2011-06-27 18:53

Well, if he uses fall-throughs it might be a good idea. Otherwise, no.

Name: Anonymous 2011-06-27 22:54

I know a guy that says you should replace every switch with a vtable

Name: Anonymous 2011-06-27 23:03

>>6
you know Bjarne too?

Name: Anonymous 2011-06-27 23:11

I know a guy that says you should replace every switch with a case

Name: Anonymous 2011-06-27 23:18

I know a guy that says he is gonna replace every scientist with an artist

Name: Anonymous 2011-06-28 0:45


int x = 1;
switch(x==1){
  case 0: printf("false"); break;
  default: printf("true");
}

Name: Anonymous 2011-06-28 1:23

<-- dubz, check'em

Name: Anonymous 2011-06-28 2:29

Zwölf.

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);
        }
}

Name: Anonymous 2011-06-28 3:56

"GRUNNUR"

Name: Anonymous 2011-06-28 4:44

I know a guy

Name: Anonymous 2011-06-28 7:51

decent benchmarks or gtfo

Name: Anonymous 2011-06-28 11:51

>2011
>Not using hashmaps with function pointers

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.

Name: Anonymous 2011-06-28 14:41

>>17
faggot

Name: Anonymous 2011-06-28 15:21

i know no one cose im a autist :(

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.

Name: >>10 2011-06-28 16:07

>>21

switch(x < 0){
  case 0: result = sqrt(x); break;
  default: result = 0;
}

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.

Name: Anonymous 2011-06-28 19:41

>>22
INB4 SHITSTORM!

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
Don't change these.
Name: Email:
Entire Thread Thread List