uassert.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. *
  6. * Copyright (C) 2002-2011, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. *
  11. * File uassert.h
  12. *
  13. * Contains the U_ASSERT and UPRV_UNREACHABLE macros
  14. *
  15. ******************************************************************************
  16. */
  17. #ifndef U_ASSERT_H
  18. #define U_ASSERT_H
  19. /* utypes.h is included to get the proper define for uint8_t */
  20. #include "unicode/utypes.h"
  21. /* for abort */
  22. #include <stdlib.h>
  23. /**
  24. * \def U_ASSERT
  25. * By default, U_ASSERT just wraps the C library assert macro.
  26. * By changing the definition here, the assert behavior for ICU can be changed
  27. * without affecting other non - ICU uses of the C library assert().
  28. */
  29. #if U_DEBUG
  30. # include <assert.h>
  31. # define U_ASSERT(exp) assert(exp)
  32. #elif U_CPLUSPLUS_VERSION
  33. # define U_ASSERT(exp) void()
  34. #else
  35. # define U_ASSERT(exp)
  36. #endif
  37. /**
  38. * \def UPRV_UNREACHABLE
  39. * This macro is used to unconditionally abort if unreachable code is ever executed.
  40. * @internal
  41. */
  42. #if defined(UPRV_UNREACHABLE)
  43. // Use the predefined value.
  44. #else
  45. # define UPRV_UNREACHABLE abort()
  46. #endif
  47. #endif