It has been [0] days since I forgot to add a break in a case in C, leading to a fallthrough corrupting memory.
@samir Oof. C23 and C++17 have a [[fallthrough]] attribute, so compilers really ought to just default to unannotated fallthrough being an error.
@aiusepsi I gotta figure out how to turn on way more warnings, at least!

@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.

Compiler Explorer - C

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”?

@aiusepsi I checked and I had -Wall and -Wpedantic turned on, but not -Wextra. Why are computers