@@ -44,7 +44,7 @@ extern "C" {
4444 * CFLAGS += -DDEBUG_ASSERT_VERBOSE
4545 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4646 */
47- #define DEBUG_ASSERT_VERBOSE
47+ # define DEBUG_ASSERT_VERBOSE
4848
4949/**
5050 * @brief Activate breakpoints for @ref assert() when defined
@@ -58,32 +58,39 @@ extern "C" {
5858 * execution is stopped directly in the debugger. Otherwise the execution stops
5959 * in an endless while loop.
6060 */
61- #define DEBUG_ASSERT_BREAKPOINT
61+ # define DEBUG_ASSERT_BREAKPOINT
6262#else
6363/* we should not include custom headers in standard headers */
64- #define _likely (x ) __builtin_expect((uintptr_t)(x), 1)
64+ # define _likely (x ) __builtin_expect((uintptr_t)(x), 1)
6565#endif
6666
67+ #ifndef __NORETURN
68+ # if defined(__GNUC__ ) || defined(DOXYGEN )
6769/**
68- * @def __NORETURN
69- * @brief hidden (__) NORETURN definition
70+ * @brief Same as @ref NORETURN
7071 * @internal
7172 *
72- * Duplicating the definitions of kernel_defines.h as these are unsuitable for
73- * system header files like the assert.h.
74- * kernel_defines.h would define symbols that are not reserved.
73+ * We are not using @ref NORETURN from `compiler_hints.h` here to avoid RIOT
74+ * dependencies for standard C headers
7575 */
76- #ifndef __NORETURN
77- #ifdef __GNUC__
78- #define __NORETURN __attribute__((noreturn))
79- #else /*__GNUC__*/
80- #define __NORETURN
81- #endif /*__GNUC__*/
82- #endif /*__NORETURN*/
76+ # define __NORETURN __attribute__((noreturn))
77+ # else
78+ # define __NORETURN
79+ # endif
80+ #endif
81+
82+ /**
83+ * @brief Internal function to trigger a panic with a failed assertion as
84+ * identifying cause
85+ * @internal
86+ * @warning This is an internal function. API changes may happen without regard
87+ * for out-of tree uses.
88+ *
89+ * The implementation will identify the cause of the panic as a blown assertion,
90+ * e.g. via a log output.
91+ */
92+ __NORETURN void _assert_panic (void );
8393
84- #ifdef NDEBUG
85- #define assert (ignore )((void)0)
86- #elif defined(DEBUG_ASSERT_VERBOSE )
8794/**
8895 * @brief Function to handle failed assertion
8996 *
@@ -95,6 +102,10 @@ extern "C" {
95102 * @param[in] line The code line of @p file the assertion failed in
96103 */
97104__NORETURN void _assert_failure (const char * file , unsigned line );
105+
106+ #ifdef NDEBUG
107+ # define assert (ignore )((void)0)
108+ #elif defined(DEBUG_ASSERT_VERBOSE )
98109/**
99110 * @brief abort the program if assertion is false
100111 *
@@ -132,27 +143,26 @@ __NORETURN void _assert_failure(const char *file, unsigned line);
132143 *
133144 * @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/assert.html
134145 */
135- #define assert (cond ) (_likely(cond) ? (void)0 : _assert_failure(__FILE__, __LINE__))
146+ # define assert (cond ) (_likely(cond) ? (void)0 : _assert_failure(__FILE__, __LINE__))
136147#else /* DEBUG_ASSERT_VERBOSE */
137- __NORETURN void _assert_panic (void );
138- #define assert (cond ) (_likely(cond) ? (void)0 : _assert_panic())
148+ # define assert (cond ) (_likely(cond) ? (void)0 : _assert_panic())
139149#endif /* DEBUG_ASSERT_VERBOSE */
140150
141151#if !defined __cplusplus
142- #if __STDC_VERSION__ >= 201112L
152+ # if __STDC_VERSION__ >= 201112L
143153/**
144154 * @brief c11 static_assert() macro
145155 */
146- #define static_assert (...) _Static_assert(__VA_ARGS__)
147- #else
156+ # define static_assert (...) _Static_assert(__VA_ARGS__)
157+ # else
148158/**
149159 * @brief static_assert for c-version < c11
150160 *
151161 * Generates a division by zero compile error when cond is false
152162 */
153- #define static_assert (cond , ...) \
154- { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; }
155- #endif
163+ # define static_assert (cond , ...) \
164+ { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; }
165+ # endif
156166#endif
157167
158168/**
@@ -161,7 +171,7 @@ __NORETURN void _assert_panic(void);
161171 * If the assertion failed in an interrupt, the system will still panic.
162172 */
163173#ifndef DEBUG_ASSERT_NO_PANIC
164- #define DEBUG_ASSERT_NO_PANIC (1)
174+ # define DEBUG_ASSERT_NO_PANIC (1)
165175#endif
166176
167177#ifdef __cplusplus
0 commit comments