POSIX.1-2008 compliant version of the assert macro. More...
POSIX.1-2008 compliant version of the assert macro.
Definition in file assert.h.
#include "panic.h"
Go to the source code of this file.
#define | DEBUG_ASSERT_VERBOSE |
Activate verbose output for assert() when defined. More... | |
#define | assert(cond) |
abort the program if assertion is false More... | |
#define | static_assert(cond, ...) { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; } |
static_assert for c-version < c11 More... | |
const char | assert_crash_message [] |
the string that is passed to panic in case of a failing assertion | |
NORETURN void | _assert_failure (const char *file, unsigned line) |
Function to handle failed assertion. More... | |
#define assert | ( | cond | ) |
abort the program if assertion is false
If the macro NDEBUG was defined at the moment <assert.h> was last included, the macro assert() generates no code, and hence does nothing at all.
Otherwise, the macro assert() prints an error message to standard error and terminates the application by calling core_panic().
The purpose of this macro is to help programmers find bugs in their programs.
With DEBUG_ASSERT_VERBOSE defined this will print also the file, the line and the function this assertion failed in.
If NDEBUG
and DEBUG_ASSERT_VERBOSE are not defined, a failed assertion generates output similar to:
0x89abcdef *** RIOT kernel panic: FAILED ASSERTION. ...
Where 0x89abcdef is an address. This address can be used with tools like addr2line
(or e.g. arm-none-eabi-addr2line
for ARM-based code), objdump
, or gdb
(with the command info line *(0x89abcdef)
) to identify the line the assertion failed in.
#define DEBUG_ASSERT_VERBOSE |
Activate verbose output for assert() when defined.
Without this macro defined the assert() macro 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 CFLAGS
in your application's Makefile:
#define static_assert | ( | cond, | |
... | |||
) | { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; } |
NORETURN void _assert_failure | ( | const char * | file, |
unsigned | line | ||
) |
Function to handle failed assertion.
[in] | file | The file name of the file the assertion failed in |
[in] | line | The code line of file the assertion failed in |