]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: compiler: add a macro to ignore all arguments
authorWilly Tarreau <w@1wt.eu>
Wed, 1 Jul 2026 12:39:08 +0000 (14:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 Jul 2026 14:32:28 +0000 (16:32 +0200)
Regularly when disabling features (e.g. traces), some macros that would
make use of some arguments end up not consuming them at all, making the
compiler complain that "variable foo defined but not used".

An elegant way to generically mark arguments as used is to pass them to
a variadic function. However a first argument is needed. So we create a
macro that passes (0, __VA_ARGS__) to an inline function that does nothing
from its arguments, and that's done.

include/haproxy/compiler.h

index 3f7f3bc8ec3cfe9c24bff8582b41707222acaa56..b74e636bbe1bc72bfe978de94e95cdfa534f7b55 100644 (file)
 #  endif
 #endif
 
+/* Eats all arguments ignoring their types and contents. This is useful
+ * to avoid "foo declared but not used" warnings. A first non-empty arg
+ * is required by the function, but it's inserted by the macro.
+ */
+#define __eat_all_args(...) ___eat_all_args(0, __VA_ARGS__)
+static inline __attribute__((always_inline)) void ___eat_all_args(int ignore, ...)
+{
+       (void)ignore;
+}
+
+
 #endif /* _HAPROXY_COMPILER_H */