Abort a program if a test is false.
Compatibility:This function is compatible with the following targets:
|
Mac OS
|
|
#include <assert.h>
void assert(int expression);Parameters:
Parameters for this function are:
file: line test -- assertion failed
assert() macros, place a #define NDEBUG (no debugging) directive before the #include <assert.h> directive.
See Also:
Example of assert() usage.:#undef NDEBUG
/* Make sure that assert() is enabled */
#include <assert.h>
#include <stdio.h>
int main(void)
{
int x = 100, y = 5;
printf("assert test.\n");
/*This assert will output a message and abort the program */
assert(x > 1000);
printf("This will not execute if NDEBUG is undefined\n");
return 0;
}
/* Output:
assert test.
foo.c:12 x > 1000 -- assertion failed
abort -- terminating
*/