User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer







because of the inhumane working conditions at amazon in Germany, I will offer the Amazon app no more! (ARD Reportage)
c:assert.h:assert

Table of Contents

assert

    void assert(scalar expression);

With assert you can test your programm for logical errors.

The assert () macro will insert diagnostics into programs

When executed, if expression (which is a scalar type you have) is false (ie, compares equal to 0),
assert (), provide information about the particular call that failed to stderr and abort ()

C Sourcecode Example

#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
#include <assert.h>
 
int testfunc(int a, int b) {
   assert( (a >= 0 && a >= b) && (b >= 0) );
   return a / b;
}
 
int main ( void ) {
printf("9 / 4 = %d\n", testfunc(9, 4) );
printf("1 / 1 = %d\n", testfunc(1, 1) );
printf("0 / 9 = %d\n", testfunc(0, 9) );
return 0;
}

Output

  user@host:~$ ./assert 
  9 / 4 = 2
  1 / 1 = 1
  assert: assert.c:6: testfunc: Assertion `(a >= 0 && a >= b) && (b >= 0)' failed.
  canceled
c/assert.h/assert.txt · Last modified: 2013/02/28 18:28 by 158.181.88.241

The new Question & Answer System is online and waiting for your Questions about Programming problems http://ask.code-reference.com Impressum