home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / unixlib / h / assert < prev    next >
Encoding:
Text File  |  2006-09-17  |  1.7 KB  |  69 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/assert.h,v $
  4.  * $Date: 2005/04/13 19:20:05 $
  5.  * $Revision: 1.9 $
  6.  * $State: Exp $
  7.  * $Author: nick $
  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 <features.h>
  22. #endif
  23.  
  24. __BEGIN_DECLS
  25.  
  26. extern void assert (int) __THROW __attribute__ ((__noreturn__));
  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. # undef __ASSERT_CAST
  40. #endif /* __ASSERT_H */
  41.  
  42. #if defined __cplusplus && defined __GNUC__
  43. #define __ASSERT_CAST static_cast<void>
  44. #else
  45. #define __ASSERT_CAST (void)
  46. #endif
  47.  
  48. #ifdef NDEBUG
  49. # define assert(x) (__ASSERT_CAST (0))
  50. #else
  51. # ifdef __GNUC__
  52. /* If compiled under GCC, we can also output the function name.  */
  53. #  define assert(expr) \
  54.     (__ASSERT_CAST ((expr) || (__assert2 (#expr, __PRETTY_FUNCTION__, __FILE__, __LINE__), 0)))
  55. # else
  56.  
  57. #  ifdef __STDC__
  58. /* __func__ is defined by Norcroft C.  */
  59. #   define assert(expr) \
  60.      (__ASSERT_CAST ((expr) || (__assert2 (#expr, __func__, __FILE__, __LINE__), 0)))
  61. #  else
  62. #   define assert(expr) \
  63.      (__ASSERT_CAST ((expr) || (__assert2 ("expr", NULL, __FILE__, __LINE__), 0)))
  64. #  endif
  65.  
  66. # endif /* __GNUC__ */
  67.  
  68. #endif /* NDEBUG */
  69.