-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathassert.html
77 lines (74 loc) · 3.13 KB
/
assert.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>assert.h</TITLE>
<STYLE TYPE="TEXT/CSS">
<!--
.IE3-DUMMY { CONT-SIZE: 100%; }
BODY { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #E0E0E0; }
P { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H1 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H2 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H3 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H4 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H5 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H6 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
UL { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
TD { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #FFFFFF; }
.NOBORDER { BACKGROUND-COLOR: #E0E0E0; PADDING: 0pt; }
.NOBORDER TD { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #E0E0E0; PADDING: 0pt; }
.CODE { FONT-FAMILY: Courier New; }
-->
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#E0E0E0">
<FONT SIZE="5"><B>The <assert.h> Header File</B></FONT>
<HR>
<P><B>Assert routine for debugging purposes</B></P>
<H3><U>Functions</U></H3>
<DL INDENT="20"><DT><B><A HREF="#assert">assert</A></B><DD>Tests a condition and possibly aborts.</DL>
<HR>
<H3><A NAME="assert"><U>assert</U></A></H3>
<P><TABLE BORDER="1" CELLPADDING="2"><TR><TD CLASS="CODE"><B><A HREF="keywords.html#void">void</A></B> assert (<B><A HREF="keywords.html#short">short</A></B> condition);</TD></TR></TABLE></P>
<P><B>Tests a condition and possibly aborts.</B></P>
<P>assert is a macro for debugging purposes that expands to an if statement.
If <I>condition</I> evaluates to zero, assert opens an error message box, waits for
a keypress, then abort the program. Here is a HTMLized "picture" which shows principally
how such message box looks like:
<BR><BR>
<CENTER>
<TABLE BORDER CELLPADDING="3">
<TR><TD>
<CENTER>
<B>ASSERTION FAILED</B>
</CENTER>
</TD></TR>
<TR><TD>
<BR>
<B>Condition:</B> <I>condition_written_as_text</I>
<BR><BR>
<B>File:</B> <I>filename</I> <B>Line:</B> <I>linenum</I>
<BR><BR><BR>
<TABLE BORDER><TR><TD><B> Enter=OK </B></TD></TR></TABLE>
</TD></TR>
</TABLE>
</CENTER>
<BR>
The <I>filename</I> and <I>linenum</I> listed in the message box are the source file name and
line number where the assert macro appears. assert expands to relatively big code, so if you have
many assert statements in the program, it may become quite long relatively fast. But, if you place
the directive</P>
<PRE>#define NDEBUG
</PRE>
<P>("no debugging") in the source code before the</P>
<PRE>#include <assert.h>
</PRE>
<P>directive, the assert statement will be ignored.
<BR><BR>
It might be hard to use this function if you are compiling your program with the <A HREF="ide.html">IDE</A>
(it is possible to get wrong line numbers). In any case, turning off file splitting may be useful.</P>
<HR>
<H3><A HREF="index.html">Return to the main index</A></H3>
</BODY>
</HTML>