• Create Account

Banner advertising on our site currently available from just \$5!

### #Actuallomateron

Posted 13 June 2013 - 08:30 PM

I have this code

float Code(float a,float b, int c)

{

float r=0;

if( c==0)

{

r=a*b;

}

else if( c==1)

{

r=a/b;

}

else if( c==2)

{

r=2*a;

}

return r;

}

Lets say i don't have 3 different "if" but a thousand different "if", and "c" as it is in the code just selects one "if"

Has anyone think about a way to make this faster by creating a way of recompiling the code so it deletes all the unnecessary "if" lines in the assembly code

Or is there anything related to this that solves the problem in a different way?

### #1lomateron

Posted 13 June 2013 - 05:39 PM

I have this code

float Code(float a,float b, int c)

{

float r=0;

if( c==0)

{

r=a*b;

}

else if( c==1)

{

r=a/b;

}

else if( c==2)

{

r=2*a;

}

return r;

}

Lets say i don't have 3 different "if" but a thousand different "if", and "c" as it is in the code just selects one "if"

the variable "c" is defined when the application is running, and can be changed

Has anyone think about a way to make this faster by creating a way of recompiling the code so it deletes all the unnecessary "if" lines in the assembly code

Or is there anything related to this that solves the problem in a different way?

PARTNERS