1<html lang="en"> 2<head> 3<title>assert - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib"> 9<link rel="prev" href="abs.html#abs" title="abs"> 10<link rel="next" href="atexit.html#atexit" title="atexit"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="assert"></a> 29<p> 30Next: <a rel="next" accesskey="n" href="atexit.html#atexit">atexit</a>, 31Previous: <a rel="previous" accesskey="p" href="abs.html#abs">abs</a>, 32Up: <a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a> 33<hr> 34</div> 35 36<h3 class="section">2.5 <code>assert</code>—macro for debugging diagnostics</h3> 37 38<p><a name="index-assert-6"></a><strong>Synopsis</strong> 39<pre class="example"> #include <assert.h> 40 void assert(int <var>expression</var>); 41 42</pre> 43 <p><strong>Description</strong><br> 44Use this macro to embed debuggging diagnostic statements in 45your programs. The argument <var>expression</var> should be an 46expression which evaluates to true (nonzero) when your program 47is working as you intended. 48 49 <p>When <var>expression</var> evaluates to false (zero), <code>assert</code> 50calls <code>abort</code>, after first printing a message showing what 51failed and where: 52 53<pre class="smallexample"> Assertion failed: <var>expression</var>, file <var>filename</var>, line <var>lineno</var>, function: <var>func</var> 54</pre> 55 <p>If the name of the current function is not known (for example, 56when using a C89 compiler that does not understand __func__), 57the function location is omitted. 58 59 <p>The macro is defined to permit you to turn off all uses of 60<code>assert</code> at compile time by defining <code>NDEBUG</code> as a 61preprocessor variable. If you do this, the <code>assert</code> macro 62expands to 63 64<pre class="smallexample"> (void(0)) 65</pre> 66 <p><br> 67<strong>Returns</strong><br> 68<code>assert</code> does not return a value. 69 70 <p><br> 71<strong>Portability</strong><br> 72The <code>assert</code> macro is required by ANSI, as is the behavior 73when <code>NDEBUG</code> is defined. 74 75 <p>Supporting OS subroutines required (only if enabled): <code>close</code>, <code>fstat</code>, 76<code>getpid</code>, <code>isatty</code>, <code>kill</code>, <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>. 77 78 <p><br> 79 80 </body></html> 81 82