diff options
Diffstat (limited to 'devdocs/c/language%2Fattributes%2Ffallthrough.html')
| -rw-r--r-- | devdocs/c/language%2Fattributes%2Ffallthrough.html | 45 |
1 files changed, 45 insertions, 0 deletions
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 @@ + <h1 id="firstHeading" class="firstHeading">C attribute: fallthrough <span class="t-mark-rev t-since-c23">(since C23)</span> +</h1> <p>Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fallthrough.</p> +<h3 id="Syntax"> Syntax</h3> <table class="t-sdsc-begin"> <tr class="t-sdsc"> <td class="t-sdsc-nopad"> <code>[[</code> <code>fallthrough</code> <code>]]</code><br><code>[[</code> <code>__fallthrough__</code> <code>]]</code> </td> <td class="t-sdsc-nopad"> </td> <td class="t-sdsc-nopad"> </td> +</tr> +</table> <h3 id="Explanation"> Explanation</h3> <p>May only be used in an <a href="../declarations" title="c/language/declarations">attribute declaration</a> to create a <i>fallthrough declaration</i> (<code>[[fallthrough]];</code>).</p> +<p>A fallthrough declaration may only be used in a <a href="../switch" title="c/language/switch"><code>switch</code></a> statement, where the next block item (statement, declaration, or label) to be encounted is a statement with a <code>case</code> or <code>default</code> label for that switch statement.</p> +<p>Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fallthrough.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#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) {}</pre></div> </div> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/language/attributes/fallthrough" title="cpp/language/attributes/fallthrough">C++ documentation</a></span> for <code>fallthrough</code> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/language/attributes/fallthrough" class="_attribution-link">https://en.cppreference.com/w/c/language/attributes/fallthrough</a> + </p> +</div> |
