diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/language%2Fattributes%2Fmaybe_unused.html | |
new repository
Diffstat (limited to 'devdocs/c/language%2Fattributes%2Fmaybe_unused.html')
| -rw-r--r-- | devdocs/c/language%2Fattributes%2Fmaybe_unused.html | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/devdocs/c/language%2Fattributes%2Fmaybe_unused.html b/devdocs/c/language%2Fattributes%2Fmaybe_unused.html new file mode 100644 index 00000000..e8af27c7 --- /dev/null +++ b/devdocs/c/language%2Fattributes%2Fmaybe_unused.html @@ -0,0 +1,33 @@ + <h1 id="firstHeading" class="firstHeading">C attribute: maybe_unused <span class="t-mark-rev t-since-c23">(since C23)</span> +</h1> <p>Suppresses warnings on unused entities.</p> +<h3 id="Syntax"> Syntax</h3> <table class="t-sdsc-begin"> <tr class="t-sdsc"> <td class="t-sdsc-nopad"> <code>[[</code> <code>maybe_unused</code> <code>]]</code><br><code>[[</code> <code>__maybe_unused__</code> <code>]]</code> </td> <td class="t-sdsc-nopad"> </td> <td class="t-sdsc-nopad"> </td> +</tr> +</table> <h3 id="Explanation"> Explanation</h3> <p>This attribute can appear in the declaration of the following entities:</p> +<ul> +<li> <a href="../struct" title="c/language/struct">struct</a>/<a href="../union" title="c/language/union">union</a>: <code>struct [[maybe_unused]] S;</code>, </li> +<li> <a href="../typedef" title="c/language/typedef">typedef name</a>: <code>[[maybe_unused]] typedef S* PS;</code>, </li> +<li> object: <code>[[maybe_unused]] int x;</code>, </li> +<li> struct/union member: <code>union U { [[maybe_unused]] int n; };</code>, </li> +<li> <a href="../function_definition" title="c/language/function definition">function</a>: <code>[[maybe_unused]] void f(void);</code>, </li> +<li> <a href="../enum" title="c/language/enum">enumeration</a>: <code>enum [[maybe_unused]] E {};</code>, </li> +<li> enumerator: <code>enum { A [[maybe_unused]], B [[maybe_unused]] = 42 };</code>. </li> +</ul> <p>If the compiler issues warnings on unused entities, that warning is suppressed for any entity declared <code>maybe_unused</code>.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <assert.h> + +[[maybe_unused]] void f([[maybe_unused]] _Bool cond1, [[maybe_unused]] _Bool cond2) +{ + [[maybe_unused]] _Bool b = cond1 && cond2; + assert(b); // in release mode, assert is compiled out, and b is unused + // no warning because it is declared [[maybe_unused]] +} // parameters cond1 and cond2 are not used, no warning + +int main(void) +{ + f(1, 1); +}</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/maybe_unused" title="cpp/language/attributes/maybe unused">C++ documentation</a></span> for <code>maybe_unused</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/maybe_unused" class="_attribution-link">https://en.cppreference.com/w/c/language/attributes/maybe_unused</a> + </p> +</div> |
