assert.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 INRIA
3  * Copyright (C) 2016 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
22 #ifndef ASSERT_H
23 #define ASSERT_H
24 
25 #include "panic.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #ifdef DOXYGEN
32 
46 #define DEBUG_ASSERT_VERBOSE
47 #endif
48 
49 #ifndef RIOT_FILE_RELATIVE
50 #define RIOT_FILE_RELATIVE (__FILE__)
51 #endif
52 
56 extern const char assert_crash_message[];
57 
58 #ifdef NDEBUG
59 #define assert(ignore)((void)0)
60 #elif defined(DEBUG_ASSERT_VERBOSE)
61 
71 NORETURN void _assert_failure(const char *file, unsigned line);
72 
104 #define assert(cond) ((cond) ? (void)0 : _assert_failure(RIOT_FILE_RELATIVE, \
105  __LINE__))
106 #else
107 #define assert(cond) ((cond) ? (void)0 : core_panic(PANIC_ASSERT_FAIL, \
108  assert_crash_message))
109 #endif
110 
111 #if !defined __cplusplus
112 #if __STDC_VERSION__ >= 201112L
113 
116 #define static_assert(...) _Static_assert(__VA_ARGS__)
117 #else
118 
123 #define static_assert(cond, ...) \
124  { enum { static_assert_failed_on_div_by_0 = 1 / (!!(cond)) }; }
125 #endif
126 #endif
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* ASSERT_H */
133 
assert_crash_message
const char assert_crash_message[]
the string that is passed to panic in case of a failing assertion
NORETURN
#define NORETURN
The NORETURN keyword tells the compiler to assume that the function cannot return.
Definition: kernel_defines.h:74
_assert_failure
NORETURN void _assert_failure(const char *file, unsigned line)
Function to handle failed assertion.
panic.h
Crash handling header.