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.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /** printf() for assertions
  18. *
  19. * This function exists so that the assert() macro can expand to
  20. * printf() calls without dragging the printf() prototype into scope.
  21. *
  22. * As far as the compiler is concerned, assert_printf() and printf() are
  23. * completely unrelated calls; it's only at the assembly stage that
  24. * references to the assert_printf symbol are collapsed into references
  25. * to the printf symbol.
  26. */
  27. extern int __attribute__ (( format ( printf, 1, 2 ) ))
  28. assert_printf ( const char *fmt, ... ) asm ( "printf" );
  29. /**
  30. * Assert a condition at run-time.
  31. *
  32. * If the condition is not true, a debug message will be printed.
  33. * Assertions only take effect in debug-enabled builds (see DBG()).
  34. *
  35. * @todo Make an assertion failure abort the program
  36. *
  37. */
  38. #define assert( condition ) \
  39. do { \
  40. if ( ASSERTING && ! (condition) ) { \
  41. assert_printf ( "assert(%s) failed at %s line %d\n", \
  42. #condition, __FILE__, __LINE__ ); \
  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 */