Switch statement with automatic break at each case step in C++ -


if want have switch statement each case need run instructions break this:

switch (condition) {    case (opt1):       // stuff       break;    case (opt2):       // stuff       break;    case (opt3):         // stuff       break;    // ...    default:       // stuff } 

is possible have exclusive switch, without fall through, default every option should break , not have explicitly state break instruction? , if not in c++ idea if such feature available in other imperative languages?

c# needs break too, yells @ if don't put it. need goto label; explicitly fall through.

in c++, there no way natively (other horrible macros, of course). however, clang has -wimplicit-fallthrough warning. can insert [[clang::fallthrough]]; silence warning deliberate fallthrough.

documentation : http://clang.llvm.org/docs/attributereference.html#fallthrough-clang-fallthrough


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -