《操作系统》的实验代码。

27 righe
946 B

  1. #ifndef __KERN_DEBUG_ASSERT_H__
  2. #define __KERN_DEBUG_ASSERT_H__
  3. #include <defs.h>
  4. void __warn(const char *file, int line, const char *fmt, ...);
  5. void __noreturn __panic(const char *file, int line, const char *fmt, ...);
  6. #define warn(...) \
  7. __warn(__FILE__, __LINE__, __VA_ARGS__)
  8. #define panic(...) \
  9. __panic(__FILE__, __LINE__, __VA_ARGS__)
  10. #define assert(x) \
  11. do { \
  12. if (!(x)) { \
  13. panic("assertion failed: %s", #x); \
  14. } \
  15. } while (0)
  16. // static_assert(x) will generate a compile-time error if 'x' is false.
  17. #define static_assert(x) \
  18. switch (x) { case 0: case (x): ; }
  19. #endif /* !__KERN_DEBUG_ASSERT_H__ */