[sundance] Add reset completion check
[gpxe.git] / src / include / assert.h
blob93750a1e897b9713e80e2a480c03d847bb312099
1 #ifndef _ASSERT_H
2 #define _ASSERT_H
4 /** @file
6 * Assertions
8 * This file provides two assertion macros: assert() (for run-time
9 * assertions) and linker_assert() (for link-time assertions).
13 #ifdef NDEBUG
14 #define ASSERTING 0
15 #else
16 #define ASSERTING 1
17 #endif
19 /** printf() for assertions
21 * This function exists so that the assert() macro can expand to
22 * printf() calls without dragging the printf() prototype into scope.
24 * As far as the compiler is concerned, assert_printf() and printf() are
25 * completely unrelated calls; it's only at the assembly stage that
26 * references to the assert_printf symbol are collapsed into references
27 * to the printf symbol.
29 extern int __attribute__ (( format ( printf, 1, 2 ) ))
30 assert_printf ( const char *fmt, ... ) asm ( "printf" );
32 /**
33 * Assert a condition at run-time.
35 * If the condition is not true, a debug message will be printed.
36 * Assertions only take effect in debug-enabled builds (see DBG()).
38 * @todo Make an assertion failure abort the program
41 #define assert( condition ) \
42 do { \
43 if ( ASSERTING && ! (condition) ) { \
44 assert_printf ( "assert(%s) failed at %s line %d\n", \
45 #condition, __FILE__, __LINE__ ); \
46 } \
47 } while ( 0 )
49 /**
50 * Assert a condition at link-time.
52 * If the condition is not true, the link will fail with an unresolved
53 * symbol (error_symbol).
55 * This macro is gPXE-specific. Do not use this macro in code
56 * intended to be portable.
59 #define linker_assert( condition, error_symbol ) \
60 if ( ! (condition) ) { \
61 extern void error_symbol ( void ); \
62 error_symbol(); \
65 #endif /* _ASSERT_H */