inc/ecu/asserter.h Source File

ECU: inc/ecu/asserter.h Source File
ECU
asserter.h
Go to the documentation of this file.
1 
14 #ifndef ECU_ASSERTER_H_
15 #define ECU_ASSERTER_H_
16 
17 /*------------------------------------------------------------*/
18 /*------------------------- INCLUDES -------------------------*/
19 /*------------------------------------------------------------*/
20 
21 /* STDLib. */
22 #include <stdint.h>
23 
24 /* ECU. */
25 #include "ecu/attributes.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /*------------------------------------------------------------*/
32 /*-------------------- STATIC ASSERT MACROS ------------------*/
33 /*------------------------------------------------------------*/
34 
35 #if defined(ECU_DOXYGEN)
82  #define ECU_STATIC_ASSERT(check_, msg_)
84 #else
85  #if defined(__cplusplus) && (__cplusplus >= 201103L)
87  #define ECU_STATIC_ASSERT(check_, msg_) \
88  static_assert((check_), msg_)
89  #elif !defined(__cplusplus) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && (__STDC_VERSION__ < 202311L)
91  #define ECU_STATIC_ASSERT(check_, msg_) \
92  _Static_assert((check_), msg_)
93  #elif !defined(__cplusplus) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
95  #define ECU_STATIC_ASSERT(check_, msg_) \
96  static_assert((check_), msg_)
97  #else
100  #define ECU_STATIC_ASSERT(check_, msg_) \
101  extern const char ecu_static_assert_fired_[(check_) ? 1 : -1]
102  #endif
103 #endif /* ECU_DOXYGEN */
104 
105 /*------------------------------------------------------------*/
106 /*-------------------- RUNTIME ASSERT MACROS -----------------*/
107 /*------------------------------------------------------------*/
108 
109 #if defined(ECU_DOXYGEN)
137  #define ECU_ASSERT(check_)
138 
161  #define ECU_ASSERT_DEFINE_FILE(name_)
163 #else
164  #if !defined(ECU_DISABLE_ASSERTS)
167  #define ECU_ASSERT(check_) \
168  ((check_) ? ((void)0) : ecu_assert_handler(&ecu_file_name_[0], __LINE__))
169 
172  #define ECU_ASSERT_DEFINE_FILE(name_) \
173  static const char ecu_file_name_[] ECU_ATTRIBUTE_UNUSED = name_;
174  #else
176  #define ECU_ASSERT(check_) \
177  ((void)0)
178 
180  #define ECU_ASSERT_DEFINE_FILE(name_)
181  #endif
182 #endif /* ECU_DOXYGEN */
183 
184 /*------------------------------------------------------------*/
185 /*--------------------- PUBLIC FUNCTIONS ---------------------*/
186 /*------------------------------------------------------------*/
187 
188 #ifdef ECU_UNIT_TEST
189 /* Assert handler defined as normal function without noreturn attribute for unit tests.
190 When an assertion fires during a test control must return to the caller (the test). */
191 extern void ecu_assert_handler(const char *file, int line);
192 #else
210 ECU_ATTRIBUTE_NORETURN extern void ecu_assert_handler(const char *file, int line);
211 #endif
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 #endif /* ECU_ASSERTER_H_ */
ECU_ATTRIBUTE_NORETURN void ecu_assert_handler(const char *file, int line)
User-defined system response under an assert condition. Called by ECU_ASSERT() when an assertion fire...
#define ECU_ATTRIBUTE_NORETURN
Critical attribute. Attached to a function declaration to inform the compiler the routine never retur...
Definition: attributes.h:33