check.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. // Find how to how get function's pretty name
  6. #ifndef __FURI_CHECK_FUNC
  7. // Use g++'s demangled names in C++
  8. #if defined __cplusplus && defined __GNUC__
  9. #define __FURI_CHECK_FUNC __PRETTY_FUNCTION__
  10. // C99 requires the use of __func__
  11. #elif __STDC_VERSION__ >= 199901L
  12. #define __FURI_CHECK_FUNC __func__
  13. // Older versions of gcc don't have __func__ but can use __FUNCTION__
  14. #elif __GNUC__ >= 2
  15. #define __FURI_CHECK_FUNC __FUNCTION__
  16. // failed to detect __func__ support
  17. #else
  18. #define __FURI_CHECK_FUNC ((char*)0)
  19. #endif
  20. #endif
  21. // !__FURI_CHECK_FUNC
  22. // We have two levels of assertion
  23. // One - furi_check, which always runs, the only difference is in the level of debug information
  24. // The second is furi_assert, which doesn't compile in release mode
  25. #ifdef NDEBUG
  26. #define furi_check(__e) ((__e) ? (void)0 : __furi_check())
  27. #define furi_assert(__e) ((void)0)
  28. #else
  29. #define furi_check(__e) \
  30. ((__e) ? (void)0 : __furi_check_debug(__FILE__, __LINE__, __FURI_CHECK_FUNC, #__e))
  31. #define furi_assert(__e) \
  32. ((__e) ? (void)0 : __furi_check_debug(__FILE__, __LINE__, __FURI_CHECK_FUNC, #__e))
  33. #endif
  34. // !NDEBUG
  35. void __furi_check(void);
  36. void __furi_check_debug(const char* file, int line, const char* function, const char* condition);
  37. #ifdef __cplusplus
  38. }
  39. #endif