Expected Expression before ... In Switch Statement
This question already has an answer here:
Switch statements don't introduce new scopes. What's more, according to the C language spec, a regular statement must follow a case statement - a variable declaration is not allowed. You could put a ;
before your variable declaration and the compiler would accept it, but the variable that you defined would be in the scope of the switch's parent, which means you cannot re-declare the variable inside another case statement.
Typically when one defines variables inside of case statements, one introduces a new scope for the case statement, as in
switch(event) {
case kCFStreamEventHasBytesAvailable: {
// do stuff here
break;
}
case ...
}
链接地址: http://www.djcxy.com/p/14782.html
上一篇: 任何人都可以解释这个C程序的输出吗?
下一篇: 在Switch语句之前的预期表达式