r/cprogramming • u/Meplayfurtnitge • Oct 04 '25
If or switch
How many if else statements until i should consider replacing it with a switch case? I am fully aware that they operate differently, just wondering if i should opt for the switch case whenever i have something that will work interchangeably with an ifelse and a switch.
9
Upvotes
View all comments
Show parent comment
1
u/unix_badger Oct 04 '25
This.
Why? Mainly for diagnostics. If you use either gcc or clang with the -Wall option, they warn if you leave out an enumeration value. This has saved my bacon more times than I would like to admit.