home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / compress / zoosrc20.zoo / assert.h < prev    next >
C/C++ Source or Header  |  1989-07-25  |  1KB  |  50 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   
  18. -- use dumb assertions
  19.          assertions print a message but not the filename and line number
  20.       else
  21.          assertions print message including filename and line number
  22.       endif
  23.    endif
  24.  
  25. Note:
  26.    DUMB_ASS should be defined if the preprocessor does not support the 
  27.    varying constants __FILE__ and __LINE__, which are supposed to hold the 
  28.    name of the current file and the number of the current line.
  29.  
  30. */
  31.  
  32. #ifndef NDEBUG
  33. /* assert() macro defined only if NDEBUG is undefined */
  34. #ifdef DUMB_ASS
  35. #define assert(E) \
  36.    { if (!(E)) \
  37.       prterror ('w', "Assertion error.\n"); \
  38.    }
  39. #else
  40. /* else not DUMB_ASS */
  41. #define assert(E) \
  42.    { if (!(E)) \
  43.       prterror ('w',"Assertion error in %s:%d.\n", __FILE__, __LINE__); \
  44.    }
  45. #endif /* not DUMB_ASS */
  46. #else
  47. /* else NDEBUG */
  48. #define assert(E)
  49. #endif /* NDEBUG */
  50.