From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/language%2Fattributes%2Ffallthrough.html | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 devdocs/c/language%2Fattributes%2Ffallthrough.html (limited to 'devdocs/c/language%2Fattributes%2Ffallthrough.html') diff --git a/devdocs/c/language%2Fattributes%2Ffallthrough.html b/devdocs/c/language%2Fattributes%2Ffallthrough.html new file mode 100644 index 00000000..c1c06f6b --- /dev/null +++ b/devdocs/c/language%2Fattributes%2Ffallthrough.html @@ -0,0 +1,45 @@ +

C attribute: fallthrough (since C23) +

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

+

Syntax

+ +
[[ fallthrough ]]
[[ __fallthrough__ ]]

Explanation

May only be used in an attribute declaration to create a fallthrough declaration ([[fallthrough]];).

+

A fallthrough declaration may only be used in a switch statement, where the next block item (statement, declaration, or label) to be encounted is a statement with a case or default 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.

+

Example

#include <stdbool.h>
+ 
+void g(void) {}
+void h(void) {}
+void i(void) {}
+ 
+void f(int n) {
+  switch (n) {
+    case 1:
+    case 2:
+      g();
+     [[fallthrough]];
+    case 3: // no warning on fallthrough
+      h();
+    case 4: // compiler may warn on fallthrough
+      if(n < 3) {
+          i();
+          [[fallthrough]]; // OK
+      }
+      else {
+          return;
+      }
+    case 5:
+      while (false) {
+        [[fallthrough]]; // ill-formed: no subsequent case or default label
+      }
+    case 6:
+      [[fallthrough]]; // ill-formed: no subsequent case or default label
+  }
+}
+ 
+int main(void) {}

See also

+
C++ documentation for fallthrough
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/language/attributes/fallthrough +

+
-- cgit v1.2.3