assert_msg.h 453 B

123456789101112131415161718192021
  1. #ifndef _ASSERT_MSG_H
  2. #define _ASSERT_MSG_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #define assert_msg(M, X) ((void)((X) || \
  6. (__failed_msg((M), #X, __FILE__, __LINE__, __func__), 0)))
  7. _Noreturn static inline void
  8. __failed_msg(const char *msg, const char *expr, const char *file, int line,
  9. const char *func)
  10. {
  11. fprintf(stderr, "Assertion failed: %s: %s (%s: %s: %d)\n",
  12. msg, expr, file, func, line);
  13. abort();
  14. }
  15. #endif /* _ASSERT_MSG_H */