assert.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 1991,1992,1994-2001,2003,2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /*
  16. * ISO C99 Standard: 7.2 Diagnostics <assert.h>
  17. */
  18. #ifdef _ASSERT_H
  19. # undef _ASSERT_H
  20. # undef assert
  21. # undef __ASSERT_VOID_CAST
  22. #endif /* assert.h */
  23. #define _ASSERT_H 1
  24. #include <features.h>
  25. #if defined __cplusplus && __GNUC_PREREQ (2,95)
  26. # define __ASSERT_VOID_CAST static_cast<void>
  27. #else
  28. # define __ASSERT_VOID_CAST (void)
  29. #endif
  30. /* void assert (int expression);
  31. If NDEBUG is defined, do nothing.
  32. If not, and EXPRESSION is zero, print an error message and abort. */
  33. #ifdef NDEBUG
  34. # define assert(expr) (__ASSERT_VOID_CAST (0))
  35. #else /* Not NDEBUG. */
  36. __BEGIN_DECLS
  37. /* This prints an "Assertion failed" message and aborts. */
  38. extern void __assert(const char *, const char *, unsigned int, const char *)
  39. __THROW __attribute__ ((__noreturn__));
  40. libc_hidden_proto(__assert)
  41. __END_DECLS
  42. # define assert(expr) \
  43. (__ASSERT_VOID_CAST ((expr) ? 0 : \
  44. (__assert (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
  45. /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
  46. which contains the name of the function currently being defined.
  47. This is broken in G++ before version 2.6.
  48. C9x has a similar variable called __func__, but prefer the GCC one since
  49. it demangles C++ function names. */
  50. # if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
  51. # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
  52. # else
  53. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  54. # define __ASSERT_FUNCTION __func__
  55. # else
  56. # define __ASSERT_FUNCTION ((__const char *) 0)
  57. # endif
  58. # endif
  59. #endif /* NDEBUG. */