assert.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef __ASSERT_H
  2. #define __ASSERT_H
  3. #include <features.h>
  4. /* If NDEBUG is defined, do nothing.
  5. If not, and EXPRESSION is zero, print an error message and abort. */
  6. #ifdef NDEBUG
  7. #define assert(expr) ((void) 0)
  8. #else /* Not NDEBUG. */
  9. extern void __assert __P((const char *, const char *, int, const char *));
  10. #define assert(expr) \
  11. ((void) ((expr) || \
  12. (__assert (__STRING(expr), \
  13. __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
  14. /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
  15. which contains the name of the function currently being defined.
  16. # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
  17. This is broken in G++ before version 2.6.
  18. C9x has a similar variable called __func__, but prefer the GCC one since
  19. it demangles C++ function names. */
  20. # ifdef __GNUC__
  21. # if __GNUC__ > 2 || (__GNUC__ == 2 \
  22. && __GNUC_MINOR__ >= (defined __cplusplus ? 6 : 4))
  23. # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
  24. # else
  25. # define __ASSERT_FUNCTION ((__const char *) 0)
  26. # endif
  27. # else
  28. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  29. # define __ASSERT_FUNCTION __func__
  30. # else
  31. # define __ASSERT_FUNCTION ((__const char *) 0)
  32. # endif
  33. # endif
  34. #endif /* NDEBUG. */
  35. #endif /* __ASSERT_H */