mirror of https://gerrit.osmocom.org/libosmocore
core/utils.h: wrap OSMO_ASSERT() with do { ... } while (0)
Using do-while is a common practice for complex macros. This allows invoking OSMO_ASSERT in simple if-else statements without braces. Change-Id: I42d9c315c9c30bce828564a63c496ee62e5c1431
This commit is contained in:
parent
e59e839dd9
commit
9ac355ad51
|
@ -111,9 +111,11 @@ do { \
|
||||||
* the predicate evaluates to false (0).
|
* the predicate evaluates to false (0).
|
||||||
*/
|
*/
|
||||||
#define OSMO_ASSERT(exp) \
|
#define OSMO_ASSERT(exp) \
|
||||||
|
do { \
|
||||||
if (!(exp)) { \
|
if (!(exp)) { \
|
||||||
osmo_panic("Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
|
osmo_panic("Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
|
||||||
}
|
} \
|
||||||
|
} while (0); /* some code invokes OSMO_ASSERT() without the semicolon */
|
||||||
|
|
||||||
/*! duplicate a string using talloc and release its prior content (if any)
|
/*! duplicate a string using talloc and release its prior content (if any)
|
||||||
* \param[in] ctx Talloc context to use for allocation
|
* \param[in] ctx Talloc context to use for allocation
|
||||||
|
|
Loading…
Reference in New Issue