2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
2005-10-29 05:21:08 +08:00
|
|
|
<<assert>>---macro for debugging diagnostics
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
INDEX
|
|
|
|
assert
|
|
|
|
|
2017-11-30 16:17:18 +08:00
|
|
|
SYNOPSIS
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <assert.h>
|
|
|
|
void assert(int <[expression]>);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Use this macro to embed debuggging diagnostic statements in
|
|
|
|
your programs. The argument <[expression]> should be an
|
|
|
|
expression which evaluates to true (nonzero) when your program
|
|
|
|
is working as you intended.
|
|
|
|
|
|
|
|
When <[expression]> evaluates to false (zero), <<assert>>
|
|
|
|
calls <<abort>>, after first printing a message showing what
|
|
|
|
failed and where:
|
|
|
|
|
2007-06-27 20:44:41 +08:00
|
|
|
. Assertion failed: <[expression]>, file <[filename]>, line <[lineno]>, function: <[func]>
|
|
|
|
|
|
|
|
If the name of the current function is not known (for example,
|
|
|
|
when using a C89 compiler that does not understand __func__),
|
|
|
|
the function location is omitted.
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
The macro is defined to permit you to turn off all uses of
|
|
|
|
<<assert>> at compile time by defining <<NDEBUG>> as a
|
|
|
|
preprocessor variable. If you do this, the <<assert>> macro
|
|
|
|
expands to
|
|
|
|
|
|
|
|
. (void(0))
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
<<assert>> does not return a value.
|
|
|
|
|
|
|
|
PORTABILITY
|
|
|
|
The <<assert>> macro is required by ANSI, as is the behavior
|
|
|
|
when <<NDEBUG>> is defined.
|
|
|
|
|
|
|
|
Supporting OS subroutines required (only if enabled): <<close>>, <<fstat>>,
|
|
|
|
<<getpid>>, <<isatty>>, <<kill>>, <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-10-09 00:44:10 +08:00
|
|
|
#ifndef HAVE_ASSERT_FUNC
|
2007-06-27 20:44:41 +08:00
|
|
|
/* func can be NULL, in which case no function information is given. */
|
2000-02-18 03:39:52 +08:00
|
|
|
void
|
2017-12-04 11:43:30 +08:00
|
|
|
__assert_func (const char *file,
|
2017-12-04 09:31:41 +08:00
|
|
|
int line,
|
|
|
|
const char *func,
|
2000-02-18 03:39:52 +08:00
|
|
|
const char *failedexpr)
|
|
|
|
{
|
2007-06-27 20:44:41 +08:00
|
|
|
fiprintf(stderr,
|
|
|
|
"assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
|
|
|
|
failedexpr, file, line,
|
|
|
|
func ? ", function: " : "", func ? func : "");
|
2000-02-18 03:39:52 +08:00
|
|
|
abort();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2009-10-09 00:44:10 +08:00
|
|
|
#endif /* HAVE_ASSERT_FUNC */
|
2007-06-27 20:44:41 +08:00
|
|
|
|
|
|
|
void
|
2017-12-04 11:43:30 +08:00
|
|
|
__assert (const char *file,
|
2017-12-04 09:31:41 +08:00
|
|
|
int line,
|
2007-06-27 20:44:41 +08:00
|
|
|
const char *failedexpr)
|
|
|
|
{
|
|
|
|
__assert_func (file, line, NULL, failedexpr);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|