assert.h¶
POSIX.1-2008 compliant version of the assert macro.
-
DEBUG_ASSERT_VERBOSE¶ Activate verbose output for
assert.h::assertwhen defined.Without this macro defined the
assert.h::assertmacro will just print the address of the code line the assertion failed in. With the macro defined the macro will also print the file, the code line and the function this macro failed in.To define just add it to your
CFLAGSin your application’s Makefile:1
CFLAGS += -DDEBUG_ASSERT_VERBOSE
-
assert( cond)¶ abort the program if assertion is false
1
((cond) ? (void)0 : _assert_failure(RIOT_FILE_RELATIVE, __LINE__))
If the macro NDEBUG was defined at the moment <assert.h> was last included, the macro
assert.h::assertgenerates no code, and hence does nothing at all.Otherwise, the macro
assert.h::assertprints an error message to standard error and terminates the application by callingpanic.h::core_panic().The purpose of this macro is to help programmers find bugs in their programs.
With
assert.h::DEBUG_ASSERT_VERBOSEdefined this will print also the file, the line and the function this assertion failed in.If
NDEBUGandassert.h::DEBUG_ASSERT_VERBOSEare not defined, a failed assertion generates output similar to:Where 0x89abcdef is an address. This address can be used with tools like
addr2line(or e.g.arm-none-eabi-addr2linefor ARM-based code),objdump, orgdb(with the commandinfo line *(0x89abcdef)) to identify the line the assertion failed in.
-
static_assert( cond, …)¶ static_assert for c-version < c11
1
enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }
Generates a division by zero compile error when cond is false
-
const char
assert_crash_message()¶ the string that is passed to panic in case of a failing assertion
-
kernel_defines.h::NORETURNvoid_assert_failure(const char * file, unsigned line)¶ Function to handle failed assertion.
Note
This function was introduced for memory size optimization
Parameters
file: The file name of the file the assertion failed in line: The code line of filethe assertion failed in