Mail Archives: djgpp/1999/08/07/08:44:17
Brian Ronk wrote:
> I got an error in a switch statement: case bypasses local variable initialization. any ideas what it is and how to fix?
>
> Brian Ronk
interesting error? This is a standard ANSI <B>C</B> (i think) violation.
You never, ever, ever, declare a variable in one case and use it in another. Keep the declarations out of the switch
statement, or make them active only from case X: to the break;
If you think you've done that, just check, make sure you're not reusing possibly active variable names. And check to make
sure all your case statements have their appropriate breaks (so there's no unintended fall through that gcc happened to get
annoyed over).
for safety, do this
case X:
{
//code
break;
}
So that there's no variable leakage possible
If you post your code, I think we can find the problem, and better suggest remedy tho.
moogla
- Raw text -