iPXE
Macros | Functions | Variables
assert.h File Reference

Assertions. More...

Go to the source code of this file.

Macros

#define ASSERTING   1
 
#define ASSERTED   ( ASSERTING && ( assertion_failures != 0 ) )
 
#define assert(condition)
 Assert a condition at run-time. More...
 
#define static_assert(x)   _Static_assert( x, #x )
 Assert a condition at build time. More...
 
#define build_assert(condition)
 Assert a condition at build time (after dead code elimination) More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int __attribute__ ((format(printf, 1, 2))) assert_printf(const char *fmt
 printf() for assertions More...
 
int asm ("printf")
 

Variables

unsigned int assertion_failures
 Number of assertion failures triggered. More...
 

Detailed Description

Assertions.

This file provides two assertion macros: assert() (for run-time assertions) and linker_assert() (for link-time assertions).

Definition in file assert.h.

Macro Definition Documentation

◆ ASSERTING

#define ASSERTING   1

Definition at line 19 of file assert.h.

◆ ASSERTED

#define ASSERTED   ( ASSERTING && ( assertion_failures != 0 ) )

Definition at line 25 of file assert.h.

◆ assert

#define assert (   condition)
Value:
do { \
if ( ASSERTING && ! (condition) ) { \
assertion_failures++; \
assert_printf ( "assert(%s) failed at %s line %d\n", \
#condition, __FILE__, __LINE__ ); \
} \
} while ( 0 )
#define ASSERTING
Definition: assert.h:19

Assert a condition at run-time.

If the condition is not true, a debug message will be printed. Assertions only take effect in debug-enabled builds (see DBG()).

Todo:
Make an assertion failure abort the program

Definition at line 49 of file assert.h.

◆ static_assert

#define static_assert (   x)    _Static_assert( x, #x )

Assert a condition at build time.

If the compiler cannot prove that the condition is true, the build will fail with an error message.

Definition at line 65 of file assert.h.

◆ build_assert

#define build_assert (   condition)
Value:
do { \
if ( ! (condition) ) { \
extern void __attribute__ (( warning ( \
"build_assert(" #condition ") failed" \
) )) _C2 ( build_assert_, __LINE__ ) ( void ); \
_C2 ( build_assert_, __LINE__ ) (); \
} \
} while ( 0 )
int __attribute__((format(printf, 1, 2))) assert_printf(const char *fmt
printf() for assertions
EFI_SYSTEM_TABLE * _C2(PLATFORM, _systab)
System table passed to entry point.

Assert a condition at build time (after dead code elimination)

If the compiler cannot prove that the condition is true, the build will fail with an error message.

This macro is iPXE-specific. Do not use this macro in code intended to be portable.

Definition at line 76 of file assert.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

int __attribute__ ( (format(printf, 1, 2))  ) const

printf() for assertions

This function exists so that the assert() macro can expand to printf() calls without dragging the printf() prototype into scope.

As far as the compiler is concerned, assert_printf() and printf() are completely unrelated calls; it's only at the assembly stage that references to the assert_printf symbol are collapsed into references to the printf symbol.

◆ asm()

int asm ( "printf"  )

Variable Documentation

◆ assertion_failures

unsigned int assertion_failures

Number of assertion failures triggered.

Definition at line 35 of file assert.c.

Referenced by run_tests().