Possible Duplicate:
Why can't variables be declared in a switch statement?
switch (i){
case 'i': int i; break; } //it works
switch (i){
case 'i': int i;i=0; break; } //it also works
switch (i){
case 'i': 开发者_如何学Pythonint i=0; break; } //it ain't
Dunno the error, but this also works for me in Objective-C (strict superset of C, although I don't believe that 1) and I do this always, even when I simply return something:
switch (i) {
case 'i': { // <- curly brackets
int i = 0; break;
} // <- curly brackets
}
(1 Because a variable can be named id
in C but not in Objective-C)
精彩评论