break in a case in C, leading to a fallthrough corrupting memory.break in a case in C, leading to a fallthrough corrupting memory.@samir Looks like GCC diagnoses unannotated fallthrough with -Wextra, and Clang does with -Weverything. Could add -Wimplicit-fallthrough to either, I suppose. https://godbolt.org/z/3Tco91845
What I do at work is turn on every warning I can get my hands on, and then selectively disable anything which is too annoying.

int test(int num); int test2(int num); int test(int num) { int i = -1; switch(num) { case 0: i = 0; case 1: i = 1; break; default: i = num; break; } return i; } int test2(int num) { int i = -1; switch(num) { case 0: i = 0; [[fallthrough]]; case 1: i = 1; break; default: i = num; break; } return i; }
@aiusepsi That’s what I do in other languages but I haven’t had much experience with C in anger, so I’m still learning. Thanks for the tips! I will enable -Wextra. (I already enabled -Wall.)
Why is it that every language has a flag for “all warnings” and then another one for “no seriously, all warnings”?