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.

assert.h 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef _ASSERT_H
  2. #define _ASSERT_H
  3. /** @file
  4. *
  5. * Assertions
  6. *
  7. * This file provides two assertion macros: assert() (for run-time
  8. * assertions) and linker_assert() (for link-time assertions).
  9. *
  10. */
  11. /**
  12. * Assert a condition at run-time.
  13. *
  14. * If the condition is not true, a debug message will be printed.
  15. * Assertions only take effect in debug-enabled builds (see DBG()).
  16. *
  17. * @todo Make an assertion failure abort the program
  18. *
  19. */
  20. #define assert( condition ) \
  21. do { \
  22. if ( ! (condition) ) { \
  23. printf ( "assert(%s) failed at %s line %d [%s]\n", \
  24. #condition, __FILE__, __LINE__, \
  25. __FUNCTION__ ); \
  26. } \
  27. } while ( 0 )
  28. /**
  29. * Assert a condition at link-time.
  30. *
  31. * If the condition is not true, the link will fail with an unresolved
  32. * symbol (error_symbol).
  33. *
  34. * This macro is gPXE-specific. Do not use this macro in code
  35. * intended to be portable.
  36. *
  37. */
  38. #define linker_assert( condition, error_symbol ) \
  39. if ( ! (condition) ) { \
  40. extern void error_symbol ( void ); \
  41. error_symbol(); \
  42. }
  43. #ifdef NDEBUG
  44. #undef assert
  45. #define assert(x) do {} while ( 0 )
  46. #endif
  47. #endif /* _ASSERT_H */