@@ -44,7 +44,7 @@ extern "C" {
44
44
* CFLAGS += -DDEBUG_ASSERT_VERBOSE
45
45
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46
46
*/
47
- #define DEBUG_ASSERT_VERBOSE
47
+ # define DEBUG_ASSERT_VERBOSE
48
48
49
49
/**
50
50
* @brief Activate breakpoints for @ref assert() when defined
@@ -58,32 +58,39 @@ extern "C" {
58
58
* execution is stopped directly in the debugger. Otherwise the execution stops
59
59
* in an endless while loop.
60
60
*/
61
- #define DEBUG_ASSERT_BREAKPOINT
61
+ # define DEBUG_ASSERT_BREAKPOINT
62
62
#else
63
63
/* 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)
65
65
#endif
66
66
67
+ #ifndef __NORETURN
68
+ # if defined(__GNUC__ ) || defined(DOXYGEN )
67
69
/**
68
- * @def __NORETURN
69
- * @brief hidden (__) NORETURN definition
70
+ * @brief Same as @ref NORETURN
70
71
* @internal
71
72
*
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
75
75
*/
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 );
83
93
84
- #ifdef NDEBUG
85
- #define assert (ignore )((void)0)
86
- #elif defined(DEBUG_ASSERT_VERBOSE )
87
94
/**
88
95
* @brief Function to handle failed assertion
89
96
*
@@ -95,6 +102,10 @@ extern "C" {
95
102
* @param[in] line The code line of @p file the assertion failed in
96
103
*/
97
104
__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 )
98
109
/**
99
110
* @brief abort the program if assertion is false
100
111
*
@@ -132,27 +143,26 @@ __NORETURN void _assert_failure(const char *file, unsigned line);
132
143
*
133
144
* @see http://pubs.opengroup.org/onlinepubs/9699919799/functions/assert.html
134
145
*/
135
- #define assert (cond ) (_likely(cond) ? (void)0 : _assert_failure(__FILE__, __LINE__))
146
+ # define assert (cond ) (_likely(cond) ? (void)0 : _assert_failure(__FILE__, __LINE__))
136
147
#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())
139
149
#endif /* DEBUG_ASSERT_VERBOSE */
140
150
141
151
#if !defined __cplusplus
142
- #if __STDC_VERSION__ >= 201112L
152
+ # if __STDC_VERSION__ >= 201112L
143
153
/**
144
154
* @brief c11 static_assert() macro
145
155
*/
146
- #define static_assert (...) _Static_assert(__VA_ARGS__)
147
- #else
156
+ # define static_assert (...) _Static_assert(__VA_ARGS__)
157
+ # else
148
158
/**
149
159
* @brief static_assert for c-version < c11
150
160
*
151
161
* Generates a division by zero compile error when cond is false
152
162
*/
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
156
166
#endif
157
167
158
168
/**
@@ -161,7 +171,7 @@ __NORETURN void _assert_panic(void);
161
171
* If the assertion failed in an interrupt, the system will still panic.
162
172
*/
163
173
#ifndef DEBUG_ASSERT_NO_PANIC
164
- #define DEBUG_ASSERT_NO_PANIC (1)
174
+ # define DEBUG_ASSERT_NO_PANIC (1)
165
175
#endif
166
176
167
177
#ifdef __cplusplus
0 commit comments