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
Post a Comment