assert.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * This file has no copyright assigned and is placed in the Public Domain.
  3. * This file is part of the mingw-w64 runtime package.
  4. * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  5. */
  6. /* According to C99 standard (section 7.2) the assert
  7. macro shall be redefined each time assert.h gets
  8. included depending on the status of NDEBUG macro. */
  9. #undef assert
  10. #ifndef __ASSERT_H_
  11. #define __ASSERT_H_
  12. #include <crtdefs.h>
  13. #ifdef __cplusplus
  14. #include <stdlib.h>
  15. #endif
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. _CRTIMP void __cdecl _wassert(const wchar_t *_Message,const wchar_t *_File,unsigned _Line);
  20. _CRTIMP void __cdecl _assert (const char *_Message, const char *_File, unsigned _Line);
  21. #ifdef __cplusplus
  22. }
  23. #endif
  24. #endif /* !defined (__ASSERT_H_) */
  25. #if (defined _ISOC11_SOURCE \
  26. || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)) \
  27. && !defined (__cplusplus)
  28. /* Static assertion. Requires support in the compiler. */
  29. #undef static_assert
  30. #define static_assert _Static_assert
  31. #endif
  32. #ifdef NDEBUG
  33. #define assert(_Expression) ((void)0)
  34. #else /* !defined (NDEBUG) */
  35. #if defined(_UNICODE) || defined(UNICODE)
  36. #define assert(_Expression) \
  37. (void) \
  38. ((!!(_Expression)) || \
  39. (_wassert(_CRT_WIDE(#_Expression),_CRT_WIDE(__FILE__),__LINE__),0))
  40. #else /* not unicode */
  41. #define assert(_Expression) \
  42. (void) \
  43. ((!!(_Expression)) || \
  44. (_assert(#_Expression,__FILE__,__LINE__),0))
  45. #endif /* _UNICODE||UNICODE */
  46. #endif /* !defined (NDEBUG) */