📄 assert.html
字号:
<HTML><HEAD><TITLE><assert.h></TITLE></HEAD><BODY><H1><A NAME="<assert.h>"><CODE><assert.h></CODE></A></H1><HR><P>Include the standard header <B><CODE><assert.h></CODE></B>to define the macro<A HREF="#assert"><CODE>assert</CODE></A>,which is useful for diagnosing logic errors inthe program. You can eliminate the testing code produced by the macro<CODE>assert</CODE> without removing the macro references from the programby defining the macro<B><A NAME="NDEBUG"><CODE>NDEBUG</CODE></A></B>in the program before you include<CODE><assert.h></CODE>. Each time the program includes this header,it redetermines the definition of the macro <CODE>assert</CODE>.</P><PRE>#undef assert#if defined NDEBUG#define <B><A HREF="#assert">assert</A></B>(test) (void)0#else#define <B><A HREF="#assert">assert</A></B>(test) <I><void expression></I>#endif</PRE><H2><A NAME="assert"><CODE>assert</CODE></A></H2><PRE>#undef assert#if defined NDEBUG#define <B>assert</B>(test) (void)0#else#define <B>assert</B>(test) <I><void expression></I>#endif</PRE><P>If the <I>int</I> expression <CODE>test</CODE> equals zero,the macro writes to<A HREF="stdio.html#stderr"><CODE>stderr</CODE></A>a diagnostic message that includes:</P><UL><LI>the text of <CODE>test</CODE></LI><LI>the source filename (the predefined macro<A HREF="preproc.html#__FILE__"><CODE>__FILE__</CODE></A>)</LI><LI>the source line number (the predefined macro<A HREF="preproc.html#__LINE__"><CODE>__LINE__</CODE></A>)</LI></UL><P>It then calls<A HREF="stdlib.html#abort"><CODE>abort</CODE></A>.</P><P>You can write the macro <CODE>assert</CODE> in the program in any<A HREF="function.html#side-effects context">side-effects context</A>.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pb.html">Copyright</A> © 1989-2002by P.J. Plauger and Jim Brodie. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -