【发布时间】:2020-07-21 08:06:00
【问题描述】:
给定代码:
#include <stdlib.h>
enum one {
A, B
};
enum two {
AA
};
int main(int argc, char *argv[])
{
enum one one = atoi(argv[1]);
enum two two = atoi(argv[2]);
if ((one != A && one != B) || two != AA)
return 1;
switch (one) {
case A:
switch (two) {
case AA:
return 2;
}
case B:
return 3;
}
return 0;
}
当我使用 gcc -Wimplicit-fallthrough test_fallthrough.c 编译它时,我收到以下警告
test_fallthrough.c: In function 'main':
test_fallthrough.c:21:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
21 | switch (two) {
| ^~~~~~
test_fallthrough.c:25:2: note: here
25 | case B:
| ^~~~
它试图警告什么,我可以做些什么使它不警告(我宁愿避免添加诸如/* Falls through. */之类的cmets)
【问题讨论】:
-
I would prefer to avoid adding comments such as /* Falls through. */what can I do so that it does not warn?使用该评论。
标签: c gcc gcc-warning