home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / zoo_src / z201src1 / assert.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-25  |  1.3 KB  |  49 lines

  1. /* @(#) assert.h 2.1 87/12/25 12:21:32 */
  2.  
  3. /*
  4. The contents of this file are hereby released to the public domain.
  5.  
  6.                            -- Rahul Dhesi 1986/11/14
  7.  
  8. Defines a macro assert() that causes an assertion error if the assertion
  9. fails.  For some useful information about this see "Reliable Data
  10. Structures in C" by Thomas Plum page 1-21.
  11.  
  12. Conditional compilation:
  13.  
  14.    If NDEBUG is defined then
  15.       assert() is defined as null so all assertions vanish
  16.    else
  17.       if DUMB_ASS is defined then   -- use dumb assertions
  18.          assertions print a message but not the filename and line number
  19.       else
  20.          assertions print message including filename and line number
  21.       endif
  22.    endif
  23.  
  24. Note:
  25.    DUMB_ASS should be defined if the preprocessor does not support the 
  26.    varying constants __FILE__ and __LINE__, which are supposed to hold the 
  27.    name of the current file and the number of the current line.
  28.  
  29. */
  30.  
  31. #ifndef NDEBUG
  32. /* assert() macro defined only if NDEBUG is undefined */
  33. #ifdef DUMB_ASS
  34. #define assert(E) \
  35.    { if (!(E)) \
  36.       prterror ('w', "Assertion error.\n"); \
  37.    }
  38. #else
  39. /* else not DUMB_ASS */
  40. #define assert(E) \
  41.    { if (!(E)) \
  42.       prterror ('w',"Assertion error in %s:%d.\n", __FILE__, __LINE__); \
  43.    }
  44. #endif /* not DUMB_ASS */
  45. #else
  46. /* else NDEBUG */
  47. #define assert(E)
  48. #endif /* NDEBUG */
  49.