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/error%2Fstatic_assert.html | |
new repository
Diffstat (limited to 'devdocs/c/error%2Fstatic_assert.html')
| -rw-r--r-- | devdocs/c/error%2Fstatic_assert.html | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/devdocs/c/error%2Fstatic_assert.html b/devdocs/c/error%2Fstatic_assert.html new file mode 100644 index 00000000..59b96576 --- /dev/null +++ b/devdocs/c/error%2Fstatic_assert.html @@ -0,0 +1,23 @@ + <h1 id="firstHeading" class="firstHeading">static_assert</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><assert.h></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 <assert.h> + +int main(void) +{ + static_assert(2 + 2 == 4, "2+2 isn't 4"); // well-formed + + static_assert(sizeof(int) < 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><assert.h></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 <assert.h> (p: 135) </li></ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.2/3 Diagnostics <assert.h> (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"> + © 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> |
