fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/27088 )
Change subject: core/utils.h: wrap OSMO_ASSERT() with do { ... } while (0) ......................................................................
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 --- M include/osmocom/core/utils.h 1 file changed, 3 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/88/27088/1
diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index 7625da1..182da08 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -111,9 +111,11 @@ * the predicate evaluates to false (0). */ #define OSMO_ASSERT(exp) \ +do { \ if (!(exp)) { \ 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) * \param[in] ctx Talloc context to use for allocation