![]() Chapter Contents |
![]() Previous |
![]() Next |
| assert |
| Portability: | ISO/ANSI C conforming, UNIX compatible |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| CAUTION | |
| USAGE NOTES | |
| EXAMPLE | |
| RELATED FUNCTIONS | |
| SEE ALSO |
| SYNOPSIS |
#include <assert.h> void assert(int expr);
| DESCRIPTION |
assert
puts diagnostics into programs.
expr
is
an expression. If the macro name
NDEBUG
is undefined at the point in the source file where
<assert.h>
is included, then
assert
expands to a statement that tests the expression. If the expression
is false (that is, compares equal to 0),
assert
writes the text of the argument, the source filename as defined by
__FILE__
, and the source line number as defined
by
__LINE__
to
stderr
(the standard error file). It then calls
abort
.
If
NDEBUG
is defined
at the point in the program where
<assert.h>
is included, then
assert
expands
to
(void *)0
.
The diagnostic is in the format of a normal library diagnostic, with the following text:
Assertion failed: expr Interrupted while: Executing line number of source-file
expr is the expression, number is the current value of
__LINE__
, and source-file is the current value of
__FILE__
.
| RETURN VALUE |
assert
has no return value.
| CAUTION |
assert
generates a library diagnostic. Because the
quiet
function suppresses library diagnostics, it also suppresses
assert
diagnostics.
You should suppress assertions by defining
NDEBUG
, not by
calling
quiet
;
quiet
will have no effect on the run-time overhead
of verifying the assertions.
| USAGE NOTES |
The macro
NDEBUG
is automatically defined by the compiler, unless you use the
DEBug
option. Suppress this automatic definition
by using the
UNdef
option or by using
NDEBUG
in a
#undef
preprocessor directive. If you use the
DEBug
option, then
NDEBUG
is not
automatically defined.
| EXAMPLE |
#include <math.h>
#include <assert.h>
#include <stdio.h>
double arcsin(double x) {
assert(x <= 1.0 && x >= -1.0);
return asin(x);
}
main()
{
double num, svalue;
puts("Enter a number.");
scanf("%f",#);
svalue = arcsin(num);
printf("The arcsin of the number is %f \n", svalue);
}
| RELATED FUNCTIONS |
| SEE ALSO |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.