Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C attribute: fallthrough(since C23)

      From cppreference.com
      <c‎ |language‎ |attributes
       
       
       
       
      Attributes
      fallthrough
      (C23)
      (C23)(C23)(deprecated)
       

      Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fallthrough.

      Contents

      [edit]Syntax

      [[fallthrough]]
      [[__fallthrough__]]

      [edit]Explanation

      May only be used in anattribute declaration to create afallthrough declaration ([[fallthrough]];).

      A fallthrough declaration may only be used in aswitch statement, where the next block item (statement, declaration, or label) to be encounted is a statement with acase ordefault label for that switch statement.

      Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fallthrough.

      [edit]Example

      Run this code
      #include <stdbool.h> void g(void){}void h(void){}void i(void){} void f(int n){switch(n){case1:case2:      g();[[fallthrough]];case3:// no warning on fallthrough      h();case4:// compiler may warn on fallthroughif(n<3){          i();[[fallthrough]];// OK}else{return;}case5:while(false){[[fallthrough]];// ill-formed: no subsequent case or default label}case6:[[fallthrough]];// ill-formed: no subsequent case or default label}} int main(void){}

      [edit]See also

      C++ documentation forfallthrough
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/language/attributes/fallthrough&oldid=124533"

      [8]ページ先頭

      ©2009-2025 Movatter.jp