assert.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.2 Diagnostics <assert.h>
  16. */
  17. #ifdef _ASSERT_H
  18. # undef _ASSERT_H
  19. # undef assert
  20. # undef __ASSERT_VOID_CAST
  21. #endif /* assert.h */
  22. #define _ASSERT_H 1
  23. #include <features.h>
  24. #if defined __cplusplus && __GNUC_PREREQ (2,95)
  25. # define __ASSERT_VOID_CAST static_cast<void>
  26. #else
  27. # define __ASSERT_VOID_CAST (void)
  28. #endif
  29. /* void assert (int expression);
  30. If NDEBUG is defined, do nothing.
  31. If not, and EXPRESSION is zero, print an error message and abort. */
  32. #ifdef NDEBUG
  33. # define assert(expr) (__ASSERT_VOID_CAST (0))
  34. #else /* Not NDEBUG. */
  35. __BEGIN_DECLS
  36. /* This prints an "Assertion failed" message and aborts. */
  37. extern void __assert(const char *, const char *, unsigned int, const char *)
  38. __THROW __attribute__ ((__noreturn__));
  39. libc_hidden_proto(__assert)
  40. __END_DECLS
  41. # define assert(expr) \
  42. (__ASSERT_VOID_CAST ((expr) ? 0 : \
  43. (__assert (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
  44. /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
  45. which contains the name of the function currently being defined.
  46. This is broken in G++ before version 2.6.
  47. C9x has a similar variable called __func__, but prefer the GCC one since
  48. it demangles C++ function names. */
  49. # if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
  50. # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
  51. # else
  52. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  53. # define __ASSERT_FUNCTION __func__
  54. # else
  55. # define __ASSERT_FUNCTION ((const char *) 0)
  56. # endif
  57. # endif
  58. #endif /* NDEBUG. */
  59. #if defined __USE_ISOC11 && !defined __cplusplus
  60. # undef static_assert
  61. # define static_assert _Static_assert
  62. #endif