As I understand, if I have a:
if(case 1)
{
char x[] = "1";
printf("%s",x);
}
else if(case 2)
{
char x[] = "12";
printf("blah-blah-blah\n");
printf("%s",x);
}
then my compiler will try to predict the branch the code will enter, and this way, to improve the execution flow. I can create my char x[MAX_SIZE]
in the head of this function and this way avoid a redundant declaration (if the branch predictor is wrong) but that would make me create a longer array than I would probably need...
Asking performance-wise: is it a good idea to move the array declaration to my function's head, or leave it inside each case of my if-else?
EDIT: I know that any performance change in this code will be very little and probably won't be recognized, but the question was about the principal.