assert.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #undef assert
  2. #ifdef __TINYC__
  3. #ifdef NDEBUG
  4. #define assert(condition) ((void)0)
  5. #else
  6. #define assert(condition) ((void)((condition) || __assertion_failed(#condition, __func__, __FILE__, __LINE__)))
  7. #endif
  8. #undef _force_assert
  9. #define _force_assert(condition) ((void)((condition) || __assertion_failed(#condition, __func__, __FILE__, __LINE__)))
  10. #ifndef __ASSERTION_FAILED
  11. #define __ASSERTION_FAILED
  12. int __assertion_failed(const char *a, const char *func, const char *file, int line);
  13. #include "stdio.h"
  14. #include "stdlib.h"
  15. int __assertion_failed(const char *a, const char *func, const char *file, int line) {
  16. fprintf(stderr, "ASSERTION FAILED in function %s at %s:%d: %s\n", func, file, line, a);
  17. abort();
  18. }
  19. #endif
  20. #else
  21. #ifdef NDEBUG
  22. #define assert(condition) ((void)0)
  23. #else
  24. #define assert(condition) ((void)((condition) || __assertion_failed(#condition)))
  25. #endif
  26. #undef _force_assert
  27. #define _force_assert(condition) ((void)((condition) || __assertion_failed(#condition)))
  28. #ifndef __ASSERTION_FAILED
  29. #define __ASSERTION_FAILED
  30. #include "stdio.h"
  31. #include "stdlib.h"
  32. int __assertion_failed(const char *a) {
  33. fputs("\nASSERTION FAILED: ", stderr);
  34. fputs(a, stderr);
  35. fputs("\n", stderr);
  36. abort();
  37. }
  38. #endif
  39. #endif