xref: /netbsd-src/share/man/man3/assert.3 (revision 9d6294cd4c5306da60fe4947ad62a34f34235a7c)
1*9d6294cdSpgoyette.\"	$NetBSD: assert.3,v 1.14 2016/06/01 01:31:11 pgoyette Exp $
2ee52468aSjtc.\"
3ee52468aSjtc.\" Copyright (c) 1991, 1993
4ee52468aSjtc.\"	The Regents of the University of California.  All rights reserved.
561f28255Scgd.\"
661f28255Scgd.\" Redistribution and use in source and binary forms, with or without
761f28255Scgd.\" modification, are permitted provided that the following conditions
861f28255Scgd.\" are met:
961f28255Scgd.\" 1. Redistributions of source code must retain the above copyright
1061f28255Scgd.\"    notice, this list of conditions and the following disclaimer.
1161f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright
1261f28255Scgd.\"    notice, this list of conditions and the following disclaimer in the
1361f28255Scgd.\"    documentation and/or other materials provided with the distribution.
14075022b3Sagc.\" 3. Neither the name of the University nor the names of its contributors
1561f28255Scgd.\"    may be used to endorse or promote products derived from this software
1661f28255Scgd.\"    without specific prior written permission.
1761f28255Scgd.\"
1861f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1961f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2061f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2161f28255Scgd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2261f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2361f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2461f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2561f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2661f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2761f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2861f28255Scgd.\" SUCH DAMAGE.
2961f28255Scgd.\"
30ee52468aSjtc.\"     @(#)assert.3	8.1 (Berkeley) 6/9/93
3161f28255Scgd.\"
32*9d6294cdSpgoyette.Dd June 1, 2016
3361f28255Scgd.Dt ASSERT 3
3461f28255Scgd.Os
3561f28255Scgd.Sh NAME
3661f28255Scgd.Nm assert
3761f28255Scgd.Nd expression verification macro
3861f28255Scgd.Sh SYNOPSIS
39472351e1Swiz.In assert.h
4061f28255Scgd.Fn assert expression
4161f28255Scgd.Sh DESCRIPTION
4261f28255ScgdThe
4361f28255Scgd.Fn assert
4461f28255Scgdmacro tests the given
4561f28255Scgd.Ar expression
4661f28255Scgdand if it is false,
4761f28255Scgdthe calling process is terminated.
48f02540ffSkleinkA diagnostic message, consisting of the text of the expression,
49f02540ffSkleinkthe name of the source file, the line number and the enclosing
50f02540ffSkleinkfunction,
51f02540ffSkleinkis written to
5261f28255Scgd.Em stderr
537fb7e975Sjtcand the
547fb7e975Sjtc.Xr abort 3
557fb7e975Sjtcfunction is called, effectively terminating the program.
5661f28255Scgd.Pp
5761f28255ScgdIf
5861f28255Scgd.Ar expression
5961f28255Scgdis true,
6061f28255Scgdthe
6161f28255Scgd.Fn assert
6261f28255Scgdmacro does nothing.
6361f28255Scgd.Pp
6461f28255ScgdThe
6561f28255Scgd.Fn assert
6661f28255Scgdmacro
6761f28255Scgdmay be removed at compile time with
6861f28255Scgdthe
694a0ee514Sjtc.Xr cc 1
704a0ee514Sjtcoption
714a0ee514Sjtc.Fl DNDEBUG .
7261f28255Scgd.Sh DIAGNOSTICS
7361f28255ScgdThe following diagnostic message is written to
7461f28255Scgd.Em stderr
7561f28255Scgdif
7661f28255Scgd.Ar expression
7761f28255Scgdis false:
7861f28255Scgd.Bd -literal -offset indent
79f02540ffSkleink"assertion \e"%s\e" failed: file \e"%s\e", line %d, function \e"%s\e"\en", \e
80f02540ffSkleink		    "expression", __FILE__, __LINE__, __func__);
8161f28255Scgd.Ed
824a0ee514Sjtc.Sh SEE ALSO
834a0ee514Sjtc.Xr cc 1 ,
84a2974864Swiz.Xr _DIAGASSERT 3 ,
85a2974864Swiz.Xr abort 3
867fb7e975Sjtc.Sh STANDARDS
8761f28255ScgdThe
8861f28255Scgd.Fn assert
897fb7e975Sjtcmacro conforms to
90dca9ccd3Swiz.St -isoC-99 .
91ee52468aSjtc.Sh HISTORY
92ee52468aSjtcA
931a1000bbSsnj.Nm
94ee52468aSjtcmacro appeared in
95*9d6294cdSpgoyette.At v7 .
96f02540ffSkleink.Pp
97f02540ffSkleinkInformation on the name of the enclosing function appeared in
98dca9ccd3Swiz.St -isoC-99 .
99