在Ubuntu中练习switch语句时如果case语句中不加break时会弹出来警告信息导致程序无法编译,
root@root:~/code$ g++ -Wall -W test_switch.c -o test_switch
test_switch.c: In function ‘int main()’:
test_switch.c:13:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
13 | printf("数字1\n");
| ~~~~~~^~~~~~~~~~~~~
test_switch.c:15:3: note: here
15 | case 3:
| ^~~~
test_switch.c:16:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
16 | printf("数字3\n");
| ~~~~~~^~~~~~~~~~~~~
test_switch.c:18:3: note: here
18 | case 5:
| ^~~~
这时,在编译代码时加上-w可以屏蔽报警,代码可以正常编译
root@root:~/code$ g++ -Wall -W test_switch.c -o test_switch -w