delorie.com/djgpp/doc/libc/libc_48.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

assert

Syntax

 
#define NDEBUG
#include <assert.h>

assert(expression);
assertval(expression);

Description

These macros are used to assist in debugging. The source code includes references to assert or assertval, passing them expressions that should be true (non-zero). When the expression yields false (zero), a diagnostic message is printed to the standard error stream, and the program aborts.

If you define the macro NDEBUG before including `assert.h', then these assert and assertval expand to nothing to reduce code size after debugging is done.

Return Value

assert returns 1 if its argument is non-zero, else it aborts.

assertval returns the value of its expression argument, if non-zero, else it aborts.

Portability

ANSI/ISO C C89; C99 (see note 1)
POSIX 1003.2-1992; 1003.1-2001 (see note 2)

Notes:

  1. assert is ANSI, assertval is not.
  2. assert is Posix, assertval is not.

Example

 
/* Like `strdup', but doesn't crash if the argument is NULL.  */
char * safe_strdup(const char *s)
{
  assert(s != 0);
  return strdup(s);
}


  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004