;

PDA

Click to See Complete Forum and Search --> : declaring new variables within a switch statement


keptblue
10-10-2009, 02:17 AM
hello,

does anyone know if declaring new variables within a switch statement (inside of case: break;) actually creates new variables inside those switch statements, or are the variable declarations moved to the top of the function when compiled?

i know that when declaring new variables inside a for or while loop, the compiler declares those variables at the beginning of the function. is it the same for if or switch statements?

Nidht
10-10-2009, 10:52 AM
Is this a question of how the compiler works, or whether you'd have access to the newly declared variable within the scope of the function, after the switch-case, for use in returning or for some other purpose?

keptblue
10-10-2009, 01:31 PM
i'm wondering how the compiler works... mainly, if i have a huge switch statement full of tons of different cases and each creates a lot of new variables within, does it heavily slow down the main program, or just each separate case branch?

Nidht
10-10-2009, 04:22 PM
I'm not much of an engineer when it comes to this type of stuff, so I really can't answer that question. Wish I could help!

I'm sure someone will come along and take a look eventually and have an answer for you. =)