[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


assert

Abort a program if a test is false.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <assert.h>
void assert(int expression);
Parameters:

Parameters for this function are:

expression  
int  
A boolean expression being evaluated  

Remarks:

If expression is false the assert() macro outputs a diagnostic message to stderr and calls abort(). The diagnostic message has the form

file: line test -- assertion failed

abort -- terminating

where

To turn off the assert() macros, place a #define NDEBUG (no debugging) directive before the #include <assert.h> directive.

See Also:

"abort."

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
*/


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000