When practicing the switch statement in Ubuntu, if break is not added in the case statement, the warning message will pop up, causing the program to fail to compile,
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:
| ^~~~
At this time, adding – W when compiling the code can shield the alarm, and the code can be compiled normally
root@root:~/code$ g++ -Wall -W test_switch.c -o test_switch -w
Read More:
- Gcc compiler warning solution: “extra tokens at end of ifndef directive” Tags: GCC, warning
- error: a label can only be part of a statement and a declaration is not a statement (How to Fix)
- Linux GCC compilation error: “collect2: LD returned 1 exit status”
- GCC compilation error unknown type name ‘bool’‘
- error: declaration may not appear after executable statement in block
- How to Fix Warning: Statement lambda can be replaced with expression lambda
- Compilation errors and warnings encountered in QT and their solutions
- DB2 create table error – 104 42601 illegal symbol encountered in SQL statement
- I encountered a compilation error twice: crosses initialization of…
- Installing GCC reduced version GCC 4.4.6 under Linux
- Error configuration process and project file may be invalid appear in cmake compilation
- Solve the ad schematic compilation warning (off grid net label XXX at XXX)
- Problems encountered in VS2010 compilation
- A PHP Error was encountered Severity: Warning Message: mysqli::real_connect(): Headers and client
- Warning when using numpy: runtimewarning: numpy.dtype size changed, may indicate binary incompatibility
- “Error in configuration process project files may be invalid” appears during cmake compilation
- Error in configuration process, project files may be invalid in cmake compilation
- Error: unclassifiable statement in FORTRAN do statement
- Python switch / case statement implementation method