a label can only be part of a statement and a declaration is not a statement
2017-09-05 17:14
489 查看
http://www.cnblogs.com/vanishfan/archive/2012/11/06/2756374.html
GCC:
error: a label can only be part of a statement and a declaration is not a statement
switch(a){ swtch(a){
case 1: case 1:
.................... {
.................... ...............
.................... ...............
break; ................
case 2: }
break; break;
} case 2:
break;
}
Error OK
GCC:
error: a label can only be part of a statement and a declaration is not a statement
switch(a){ swtch(a){
case 1: case 1:
.................... {
.................... ...............
.................... ...............
break; ................
case 2: }
break; break;
} case 2:
break;
}
Error OK
case1: //此块代码不能再声明变量,如果你声明变量就会报错,除非用括号括起来,这是编译器的问题,也可以说是C语言的规定。写代码的时候注意就成了。就像C语言再声明的时候不能赋值一样,记住就好了。 break; 希望对你有所帮助。
追问
找到了原因,我在case下面定义了变量,并给它赋了初值,当把定义和赋值分开就好了,或者是加上大括号。
相关文章推荐
- C语言:error: a label can only be part of a statement and a declaration is not a statement|
- switch引发的错误:a label can only be part of a statement and a declaration is not a statement
- ERROR:a label can only be part of a statement and a declaration is not a statement
- a label can only be part of a statement and a declaration is not a statement
- 错误“a label can only be part of a statement and a declaration is not a statement”解决方法
- a label can only be part of a statement and a declaration is not a statement
- error: a label can only be part of a statement and a declaration is not a statement
- error: a label can only be part of a statement and a declaration is not a statement
- a label can only be part of a statement and a declaration is not a statement
- 【转载】a label can only be part of a statement and a declaration is not a statement
- switch 错误:a label can only be part of a statement and a declaration is not a statement
- switch引发的错误 a label can only be part of a statement and a declaration is not a statement
- a label can only be part of a statement and a declaration is not a statement
- c 编译异常 switch 之a label can only be part of a statement and a declaration is not a statement
- 转:switch引发的错误:a label can only be part of a statement and a declaration is not a statement
- C语言:error: a label can only be part of a statement and a declaration is not a statement|
- 【C/C++】error: a label can only be part of a statement and a declaration is not a statement
- error: a label can only be part of a statement and a declaration is not a statement
- switch引发的错误 a label can only be part of a statement and a declaration is not a statement
- switch引发的错误 a label can only be part of a statement and a declaration is not a statement