RAD Studio |  |

assert

Header File

assert.h

Category

Diagnostic Routines

Prototype

void assert(int test);

Description

Tests a condition and possibly aborts.

assert is a macro that expands to an if statement; if test evaluates to zero, the assert macro calls the _assert function

void _RTLENTRY _EXPFUNC _assert(char * __cond, char * __file, int __line);

and aborts the program. The _assert function calls abort and asserts the following a message on stderr:

Assertion failed: test, file filename, line linenum

The filename and linenum listed in the message are the source file name and line number where the assert macro appears.

If you place the #define NDEBUG directive ("no debugging") in the source code before the #include <assert.h> directive, the macro expands to a no-op, the effect is to comment out the assert statement.

Return Value

None.

Example

Copy Code

     #include <assert.h>
     #include <stdio.h>
     #include <stdlib.h>
     struct ITEM {
        int key;
        int value;
     };
     /* add item to list, make sure list is not  null */
     void additem(struct ITEM *itemptr) {
        assert(itemptr != NULL);
        /* add item to list */
     }
     int main(void)
     {
        additem(NULL);
        return 0;
     }

Portability

POSIX | Win32 | ANSI C | ANSI C++
+ | + | + | +

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!