home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / zoo141_c.lzh / ASSERT.H < prev    next >
C/C++ Source or Header  |  1987-02-07  |  1KB  |  48 lines

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