diff options
Diffstat (limited to 'static/freebsd/man3/assert.3 3.html')
| -rw-r--r-- | static/freebsd/man3/assert.3 3.html | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/static/freebsd/man3/assert.3 3.html b/static/freebsd/man3/assert.3 3.html new file mode 100644 index 00000000..b8d9739e --- /dev/null +++ b/static/freebsd/man3/assert.3 3.html @@ -0,0 +1,109 @@ +<table class="head"> + <tr> + <td class="head-ltitle">ASSERT(3)</td> + <td class="head-vol">Library Functions Manual</td> + <td class="head-rtitle">ASSERT(3)</td> + </tr> +</table> +<div class="manual-text"> +<section class="Sh"> +<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1> +<p class="Pp"><code class="Nm">assert</code>, + <code class="Nm">static_assert</code> — <span class="Nd">expression + verification macro</span></p> +</section> +<section class="Sh"> +<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1> +<p class="Pp"><code class="In">#include + <<a class="In">assert.h</a>></code></p> +<p class="Pp"><code class="Fn">assert</code>(<var class="Fa" style="white-space: nowrap;">expression</var>);</p> +<p class="Pp"><code class="Fn">static_assert</code>(<var class="Fa" style="white-space: nowrap;">expression</var>);</p> +<p class="Pp"><code class="Fn">static_assert</code>(<var class="Fa" style="white-space: nowrap;">expression</var>, + <var class="Fa" style="white-space: nowrap;">message</var>);</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1> +<p class="Pp">The + <a class="permalink" href="#assert"><code class="Fn" id="assert">assert</code></a>() + macro tests the given <var class="Ar">expression</var> and if it is false, + the calling process is terminated. A diagnostic message is written to + <code class="Dv">stderr</code> and the function <a class="Xr">abort(3)</a> + is called, effectively terminating the program.</p> +<p class="Pp" id="assert~2">If <var class="Ar">expression</var> is true, the + <a class="permalink" href="#assert~2"><code class="Fn">assert</code></a>() + macro does nothing.</p> +<p class="Pp" id="assert~3">The + <a class="permalink" href="#assert~3"><code class="Fn">assert</code></a>() + macro may be removed at compile time by defining + <code class="Dv">NDEBUG</code> as a macro (e.g., by using the + <a class="Xr">cc(1)</a> option + <code class="Fl">-D</code><code class="Dv">NDEBUG</code>). Unlike most other + include files, <code class="In"><<a class="In">assert.h</a>></code> + may be included multiple times. Each time whether or not + <code class="Dv">NDEBUG</code> is defined determines the behavior of assert + from that point forward until the end of the unit or another include of + <code class="In"><<a class="In">assert.h</a>></code>.</p> +<p class="Pp" id="assert~4">The + <a class="permalink" href="#assert~4"><code class="Fn">assert</code></a>() + macro should only be used for ensuring the developer's expectations hold + true. It is not appropriate for regular run-time error detection.</p> +<p class="Pp" id="static_assert">The + <a class="permalink" href="#static_assert"><code class="Fn">static_assert</code></a>() + macro expands to + <a class="permalink" href="#_Static_assert"><code class="Fn" id="_Static_assert">_Static_assert</code></a>(), + and, contrarily to <code class="Fn">assert</code>(), makes assertions at + compile-time. Once the constraint is violated, the compiler produces a + diagnostic message including the string literal message, if provided. The + initial form of the <code class="Fn">_Static_assert</code>() containing a + string literal message was introduced in C11 standard, and the other form + with no string literal is to be implemented by C2x and some compilers may + lack its adoption at present.</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1> +<p class="Pp">The assertion:</p> +<div class="Bd Bd-indent"><code class="Li">assert(1 == 0);</code></div> +generates a diagnostic message similar to the following: +<div class="Bd Bd-indent"><code class="Li">Assertion failed: (1 == 0), function + main, file main.c, line 100.</code></div> +<p class="Pp">The following assert tries to assert there was no partial + read:</p> +<div class="Bd Bd-indent"><code class="Li">assert(read(fd, buf, nbytes) == + nbytes);</code></div> +However, there are two problems. First, it checks for normal conditions, rather + than conditions that indicate a bug. Second, the code will disappear if + <code class="Dv">NDEBUG</code> is defined, changing the semantics of the + program. +<p class="Pp">The following asserts that the size of the S structure is 16. + Otherwise, it produces a diagnostic message which points at the constraint + and includes the provided string literal:</p> +<div class="Bd Bd-indent"><code class="Li">static_assert(sizeof(struct S) == 16, + "size mismatch");</code></div> +If none is provided, it only points at the constraint. +</section> +<section class="Sh"> +<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE + ALSO</a></h1> +<p class="Pp"><a class="Xr">abort2(2)</a>, <a class="Xr">abort(3)</a></p> +</section> +<section class="Sh"> +<h1 class="Sh" id="STANDARDS"><a class="permalink" href="#STANDARDS">STANDARDS</a></h1> +<p class="Pp">The <code class="Fn">assert</code>() macro conforms to + <span class="St">ISO/IEC 9899:1999 + (“ISO C99”)</span>.</p> +<p class="Pp">The <code class="Fn">static_assert</code>() macro conforms to + <span class="St">ISO/IEC 9899:2011 + (“ISO C11”)</span>.</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1> +<p class="Pp">An <code class="Nm">assert</code> macro appeared in + <span class="Ux">Version 7 AT&T UNIX</span>.</p> +</section> +</div> +<table class="foot"> + <tr> + <td class="foot-date">April 20, 2021</td> + <td class="foot-os">FreeBSD 15.0</td> + </tr> +</table> |
