IAR error: a declaration cannot have a label

来源:互联网 发布:床垫品牌 知乎 编辑:程序博客网 时间:2024/05/22 06:48

原文:http://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement

[转]IAR error: a declaration cannot have a label

在使用switch时 在case 后面申请变量会出现 error: a declaration cannot have a label 的提示

原因:Case statements are only 'labels'. This means the compiler will interpret this as a jump directly to the label.The problem here is one of scope. Your curly brackets define the scope as everything inside the 'switch' statement. This means that you are left with a scope where a jump will be performed further into the code skipping the initialization. The correct way to handle this is to define a scope specific to that case statement and define your variable within it.

解决方法:在case 后面加一个{ }做相应的操作。

 


0 0
原创粉丝点击