《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
946 B

10 years ago
  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__ */