Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

assert.h 1.8KB

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