util.h 991 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2009 The RE2 Authors. All Rights Reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. #ifndef UTIL_UTIL_H_
  5. #define UTIL_UTIL_H_
  6. #define arraysize(array) (sizeof(array)/sizeof((array)[0]))
  7. #ifndef ATTRIBUTE_NORETURN
  8. #if defined(__GNUC__)
  9. #define ATTRIBUTE_NORETURN __attribute__((noreturn))
  10. #elif defined(_MSC_VER)
  11. #define ATTRIBUTE_NORETURN __declspec(noreturn)
  12. #else
  13. #define ATTRIBUTE_NORETURN
  14. #endif
  15. #endif
  16. #ifndef ATTRIBUTE_UNUSED
  17. #if defined(__GNUC__)
  18. #define ATTRIBUTE_UNUSED __attribute__((unused))
  19. #else
  20. #define ATTRIBUTE_UNUSED
  21. #endif
  22. #endif
  23. #ifndef FALLTHROUGH_INTENDED
  24. #if defined(__clang__)
  25. #define FALLTHROUGH_INTENDED [[clang::fallthrough]]
  26. #elif defined(__GNUC__) && __GNUC__ >= 7
  27. #define FALLTHROUGH_INTENDED [[gnu::fallthrough]]
  28. #else
  29. #define FALLTHROUGH_INTENDED do {} while (0)
  30. #endif
  31. #endif
  32. #ifndef NO_THREAD_SAFETY_ANALYSIS
  33. #define NO_THREAD_SAFETY_ANALYSIS
  34. #endif
  35. #endif // UTIL_UTIL_H_