assert.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #define COMPILE_TIME_ASSERT(pred) switch(0){case 0:case pred:;}
  13. /* All environments should implement warn, which prints a non-optional debug
  14. * message. All environments should also implement __abort, which
  15. * terminates the process.
  16. */
  17. void warn (const char *format, ...);
  18. void __abort(void);
  19. # define assert(test) \
  20. ({ \
  21. long _val = (long) (test); \
  22. (!(_val)) \
  23. ? ({ \
  24. warn("assert failed " __FILE__ ":%d " #test " (value:%x)\n", \
  25. __LINE__, _val); \
  26. __abort(); }) \
  27. : (void) 0; \
  28. })
  29. #endif