0

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': int i=0; break; } //it ain't
Community
  • 1
  • 1
jelly
  • 11
  • 1

1 Answers1

0

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)

  • True. I always use Clang which always defaults to C99 so I'm used to it. –  Jan 16 '11 at 13:16