QP-nano  6.9.0
Real-Time Embedded Framework
qassert.h
Go to the documentation of this file.
1
39#ifndef QASSERT_H
40#define QASSERT_H
41
52#ifdef Q_NASSERT /* Q_NASSERT defined--assertion checking disabled */
53
54 /* provide dummy (empty) definitions that don't generate any code... */
55 #define Q_DEFINE_THIS_FILE
56 #define Q_DEFINE_THIS_MODULE(name_)
57 #define Q_ASSERT(test_) ((void)0)
58 #define Q_ASSERT_ID(id_, test_) ((void)0)
59 #define Q_ALLEGE(test_) ((void)(test_))
60 #define Q_ALLEGE_ID(id_, test_) ((void)(test_))
61 #define Q_ERROR() ((void)0)
62 #define Q_ERROR_ID(id_) ((void)0)
63
64#else /* Q_NASSERT not defined--assertion checking enabled */
65
66#ifndef QP_VERSION /* is quassert.h used outside QP? */
67
68 /* provide typedefs so that qassert.h could be used "standalone"... */
69
77 typedef char char_t;
78
86 typedef int int_t;
87
88 #ifndef Q_ROM /* if NOT defined, provide the default definition */
90 #define Q_ROM
91 #endif
92
93#endif
94
109 #define Q_DEFINE_THIS_FILE \
110 static char_t const Q_ROM Q_this_module_[] = __FILE__;
111
125 #define Q_DEFINE_THIS_MODULE(name_) \
126 static char_t const Q_ROM Q_this_module_[] = name_;
127
141 #define Q_ASSERT(test_) ((test_) \
142 ? (void)0 : Q_onAssert(&Q_this_module_[0], (int_t)__LINE__))
143
160 #define Q_ASSERT_ID(id_, test_) ((test_) \
161 ? (void)0 : Q_onAssert(&Q_this_module_[0], (int_t)(id_)))
162
176 #define Q_ALLEGE(test_) Q_ASSERT(test_)
177
191 #define Q_ALLEGE_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
192
200 #define Q_ERROR() \
201 Q_onAssert(&Q_this_module_[0], (int_t)__LINE__)
202
216 #define Q_ERROR_ID(id_) \
217 Q_onAssert(&Q_this_module_[0], (int_t)(id_))
218
219#endif /* Q_NASSERT */
220
221/****************************************************************************/
222#ifdef __cplusplus
223 extern "C" {
224#endif
225
226#ifndef Q_NORETURN
228 #define Q_NORETURN void
229#endif /* Q_NORETURN */
230
259Q_NORETURN Q_onAssert(char_t const Q_ROM * const module, int_t const location);
260
261#ifdef __cplusplus
262 }
263#endif
264
273#define Q_REQUIRE(test_) Q_ASSERT(test_)
274
284#define Q_REQUIRE_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
285
292#define Q_ENSURE(test_) Q_ASSERT(test_)
293
303#define Q_ENSURE_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
304
313#define Q_INVARIANT(test_) Q_ASSERT(test_)
314
324#define Q_INVARIANT_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
325
336#define Q_ASSERT_STATIC(test_) \
337 extern int_t Q_assert_static[(test_) ? 1 : -1]
338
339#define Q_ASSERT_COMPILE(test_) Q_ASSERT_STATIC(test_)
340
342#define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0]))
343
344#endif /* QASSERT_H */
345
#define Q_NORETURN
Definition: qassert.h:228
char char_t
Definition: qassert.h:77
#define Q_ROM
Definition: qassert.h:90
int int_t
Definition: qassert.h:86
Q_NORETURN Q_onAssert(char_t const Q_ROM *const module, int_t const location)