您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

assert.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifdef NDEBUG
  12. #define ASSERTING 0
  13. #else
  14. #define ASSERTING 1
  15. #endif
  16. /** printf() for assertions
  17. *
  18. * This function exists so that the assert() macro can expand to
  19. * printf() calls without dragging the printf() prototype into scope.
  20. *
  21. * As far as the compiler is concerned, assert_printf() and printf() are
  22. * completely unrelated calls; it's only at the assembly stage that
  23. * references to the assert_printf symbol are collapsed into references
  24. * to the printf symbol.
  25. */
  26. extern int __attribute__ (( format ( printf, 1, 2 ) ))
  27. assert_printf ( const char *fmt, ... ) asm ( "printf" );
  28. /**
  29. * Assert a condition at run-time.
  30. *
  31. * If the condition is not true, a debug message will be printed.
  32. * Assertions only take effect in debug-enabled builds (see DBG()).
  33. *
  34. * @todo Make an assertion failure abort the program
  35. *
  36. */
  37. #define assert( condition ) \
  38. do { \
  39. if ( ASSERTING && ! (condition) ) { \
  40. assert_printf ( "assert(%s) failed at %s line " \
  41. "%d [%s]\n", #condition, __FILE__, \
  42. __LINE__, __FUNCTION__ ); \
  43. } \
  44. } while ( 0 )
  45. /**
  46. * Assert a condition at link-time.
  47. *
  48. * If the condition is not true, the link will fail with an unresolved
  49. * symbol (error_symbol).
  50. *
  51. * This macro is gPXE-specific. Do not use this macro in code
  52. * intended to be portable.
  53. *
  54. */
  55. #define linker_assert( condition, error_symbol ) \
  56. if ( ! (condition) ) { \
  57. extern void error_symbol ( void ); \
  58. error_symbol(); \
  59. }
  60. #endif /* _ASSERT_H */