home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !unixlib / source / clib / h / assert < prev    next >
Encoding:
Text File  |  2004-09-05  |  1.5 KB  |  62 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/assert.h,v $
  4.  * $Date: 2004/04/20 20:20:36 $
  5.  * $Revision: 1.7 $
  6.  * $State: Exp $
  7.  * $Author: joty $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /* ANSI Standard: 4.2 Diagnostics <assert.h>.  */
  12.  
  13. /* It is possible to turn assertions off and on in different functions within
  14.    a translation unit by definining (or undefining) NDEBUG and including
  15.    <assert.h> again.  */
  16.  
  17. #ifndef __ASSERT_H
  18. #define __ASSERT_H
  19.  
  20. #ifndef __UNIXLIB_FEATURES_H
  21. #include <unixlib/features.h>
  22. #endif
  23.  
  24. __BEGIN_DECLS
  25.  
  26. extern void assert (int) __THROW;
  27.  
  28. /* __assert2 is also used by Norcroft C compiler.  */
  29. extern void __assert2 (const char *__message,
  30.                const char *__function,
  31.                const char *__file,
  32.                int __line)
  33.      __THROW __attribute__ ((__noreturn__));
  34.  
  35. __END_DECLS
  36.  
  37. #else
  38. # undef assert
  39. #endif /* __ASSERT_H */
  40.  
  41. #ifdef NDEBUG
  42. # define assert(x) ((void) 0)
  43. #else
  44. # ifdef __GNUC__
  45. /* If compiled under GCC, we can also output the function name.  */
  46. #  define assert(expr) \
  47.     ((void)((expr) || (__assert2 (#expr, __PRETTY_FUNCTION__, __FILE__, __LINE__), 0)))
  48. # else
  49.  
  50. #  ifdef __STDC__
  51. /* __func__ is defined by Norcroft C.  */
  52. #   define assert(expr) \
  53.      ((void)((expr) || (__assert2 (#expr, __func__, __FILE__, __LINE__), 0)))
  54. #  else
  55. #   define assert(expr) \
  56.      ((void)((expr) || (__assert2 ("expr", NULL, __FILE__, __LINE__), 0)))
  57. #  endif
  58.  
  59. # endif /* __GNUC__ */
  60.  
  61. #endif /* NDEBUG */
  62.