Change required clang-format version to 14
[babeltrace.git] / src / common / macros.h
index a49e30e662aa32047576ba4a076d7c343d137053..34ac393f76bda366a8ad142ff4d568ba3465bb25 100644 (file)
@@ -7,6 +7,16 @@
 #ifndef _BABELTRACE_INTERNAL_H
 #define _BABELTRACE_INTERNAL_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+#define BT_EXTERN_C extern "C"
+#else
+#define BT_EXTERN_C
+#endif
+
 #define bt_max_t(type, a, b)   \
        ((type) (a) > (type) (b) ? (type) (a) : (type) (b))
 
 
 #define BT_MOVE_REF(ref)               \
        ({                              \
-               typeof(ref) _ref = ref; \
+               __typeof__(ref) _ref = ref;     \
                ref = NULL;             \
                _ref;                   \
        })
 
+/*
+ * Copied from:
+ * <https://stackoverflow.com/questions/37411809/how-to-elegantly-fix-this-unused-variable-warning/37412551#37412551>:
+ *
+ * * 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))
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
This page took 0.036904 seconds and 4 git commands to generate.