assert.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * assert.h
  3. *
  4. * Define a common interface for assertions that builds for both the PAL
  5. * and libOS.
  6. *
  7. */
  8. #ifndef ASSERT_H
  9. #define ASSERT_H
  10. #include <stdnoreturn.h>
  11. #define COMPILE_TIME_ASSERT(pred) switch(0){case 0:case (pred):;}
  12. /* All environments should implement warn, which prints a non-optional debug
  13. * message. All environments should also implement __abort, which
  14. * terminates the process.
  15. */
  16. void warn (const char *format, ...) __attribute__((format(printf, 1, 2)));
  17. noreturn void __abort(void);
  18. # define assert(test) \
  19. ({ \
  20. long _val = (long)(test); \
  21. (!(_val)) \
  22. ? ({ \
  23. warn("assert failed " __FILE__ ":%d %s (value:%lx)\n", \
  24. __LINE__, #test, _val); \
  25. __abort(); }) \
  26. : (void)0; \
  27. })
  28. #endif