【转载】a label can only be part of a statement and a declaration is not a statement
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
追问
找到了原因,我在case下面定义了变量,并给它赋了初值,当把定义和赋值分开就好了,或者是加上大括号。
本文解析了GCC编译器中出现的特定错误:alabelcanonlybepartofastatementandadeclarationisnotastatement。该错误通常发生在case标签之后尝试进行变量声明时。文章详细解释了这一限制的原因,并提供了如何避免此错误的方法。
4361

被折叠的 条评论
为什么被折叠?



