| 1. |
Why No Fall Through On Switch Statements? |
|
Answer» Many people have ASKED for a requirement that there be a BREAK between cases in a switch statement, that C's behavior of SILENTLY falling through is the cause of many bugs. In D2, implicit fall through is disallowed. You have to add a goto case; statement to explicitly state the intention of falling through. There was further request that the break statement be made implicit. The reason D doesn't change this is for the same reason that integral promotion rules and operator precedence rules were kept the same - to make code that looks the same as in C operate the same. If it had subtly different semantics, it will cause frustratingly subtle bugs. Many people have asked for a requirement that there be a break between cases in a switch statement, that C's behavior of silently falling through is the cause of many bugs. In D2, implicit fall through is disallowed. You have to add a goto case; statement to explicitly state the intention of falling through. There was further request that the break statement be made implicit. The reason D doesn't change this is for the same reason that integral promotion rules and operator precedence rules were kept the same - to make code that looks the same as in C operate the same. If it had subtly different semantics, it will cause frustratingly subtle bugs. |
|