summaryrefslogtreecommitdiff
path: root/devdocs/c/error%2Fstatic_assert.html
blob: 59b965765c3edc59d04e53eb0a8894f281ac3462 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    <h1 id="firstHeading" class="firstHeading">static_assert</h1>            <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;assert.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c11 t-until-c23"> <td> <pre data-language="c">#define static_assert _Static_assert</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> <br><span class="t-mark-rev t-until-c23">(removed in C23)</span> </td> </tr>  </table> <p>This convenience macro expands to the keyword <a href="../keyword/_static_assert" title="c/keyword/ Static assert"><code>_Static_assert</code></a>.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;assert.h&gt;
 
int main(void)
{
    static_assert(2 + 2 == 4, "2+2 isn't 4");   // well-formed
 
    static_assert(sizeof(int) &lt; sizeof(char),   // compile-time error
                  "this program requires that int is less than char");
}</pre></div> </div> <h3 id="Notes"> Notes</h3> <p>Since C23, <a href="../language/_static_assert" title="c/language/ Static assert"><code>static_assert</code></a> is itself a keyword, which may also be a predefined macro, so <a href="../error" title="c/error"><code>&lt;assert.h&gt;</code></a> no longer provides it.</p>
<h3 id="References"> References</h3>  <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.2/3 Diagnostics &lt;assert.h&gt; (p: 135) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.2/3 Diagnostics &lt;assert.h&gt; (p: 186) </li></ul>
</ul>       <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/static_assert" title="cpp/language/static assert">C++ documentation</a></span> for <code>Static Assertion</code> </td>
</tr> </table>           <div class="_attribution">
  <p class="_attribution-p">
    &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
    <a href="https://en.cppreference.com/w/c/error/static_assert" class="_attribution-link">https://en.cppreference.com/w/c/error/static_assert</a>
  </p>
</div>