X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=src%2Fcommon%2Fmacros.h;h=718a3050ccb1b4b96b9a00cf84adeb35185bdae0;hb=1778c2a4134647150b199b2b57130817144446b0;hp=a49e30e662aa32047576ba4a076d7c343d137053;hpb=e020d1340a9b5ebd7d7dbf00a2c34d2fe512a495;p=babeltrace.git diff --git a/src/common/macros.h b/src/common/macros.h index a49e30e6..718a3050 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -44,4 +44,31 @@ _ref; \ }) +/* + * Copied from: + * : + * + * * sizeof() ensures that the expression is not evaluated at all, so + * its side-effects don't happen. That is to be consistent with the + * usual behaviour of debug-only constructs, such as assert(). + * + * * `((_expr), 0)` uses the comma operator to swallow the actual type + * of `(_expr)`. This is to prevent VLAs from triggering evaluation. + * + * * `(void)` explicitly ignores the result of `(_expr)` and sizeof() so + * no "unused value" warning appears. + */ + +#define BT_USE_EXPR(_expr) ((void) sizeof((void) (_expr), 0)) +#define BT_USE_EXPR2(_expr1, _expr2) \ + ((void) sizeof((void) (_expr1), (void) (_expr2), 0)) +#define BT_USE_EXPR3(_expr1, _expr2, _expr3) \ + ((void) sizeof((void) (_expr1), (void) (_expr2), (void) (_expr3), 0)) +#define BT_USE_EXPR4(_expr1, _expr2, _expr3, _expr4) \ + ((void) sizeof((void) (_expr1), (void) (_expr2), \ + (void) (_expr3), (void) (_expr4), 0)) +#define BT_USE_EXPR5(_expr1, _expr2, _expr3, _expr4, _expr5) \ + ((void) sizeof((void) (_expr1), (void) (_expr2), \ + (void) (_expr3), (void) (_expr4), (void) (_expr5), 0)) + #endif