GCC with -Wextra will warn if you have an unmarked fallthrough in a switch for instance (but not with -Wall).īut beyond that I do agree that if I could go back in time and tell Dennis Ritchie to change some things about the language "make switch break by default and add a fallthrough keyword when you actually want the behaviour" would be very high on the list. It can even be less error prone in these situations since compilers will (sometimes) warn if you don't match all possible values of an enum, which is nice if you add a state to your machine and forget to update it everywhere.įortunately these days there are compiler warnings to alleviate some of the risks. It does make it very nice to write some things, in particular state machines. I do agree that it's very poorly designed since it makes it very easy to shoot yourself in the foot. Where the else statement executes if none of the if or else if statements are true.I sorta see where you're coming from, but I can't really see myself avoiding switch entirely in C. This is comparable to the else statement of if…else decision-making statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |