assert.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /*
  4. * assert.h
  5. *
  6. * Define a common interface for assertions that builds for both the PAL
  7. * and libOS.
  8. *
  9. */
  10. #ifndef ASSERT_H
  11. #define ASSERT_H
  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, ...);
  17. void __abort(void);
  18. # define assert(test) \
  19. ({ \
  20. long _val = (long) (test); \
  21. (!(_val)) \
  22. ? ({ \
  23. warn("assert failed " __FILE__ ":%d " #test " (value:%x)\n", \
  24. __LINE__, _val); \
  25. __abort(); }) \
  26. : (void) 0; \
  27. })
  28. #endif