From 69ac4cd315f05c69f3c34f824ef4e7f3221966cf Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 12 Mar 2025 18:08:12 +0100 Subject: [PATCH] MINOR: compiler: add a new __decl_thread_var() macro to declare local variables __decl_thread() already exists but is more suited for struct members. When using it in a variables block, it appends the final trailing semi-colon which is a statement that ends the variable block. Better clean this up and have one precisely for variable blocks. In this case we can simply define an unused enum value that will consume the semi-colon. That's what the new macro __decl_thread_var() does. --- include/haproxy/compiler.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index de55fe95b..c19d2c46a 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -503,6 +503,18 @@ #define __decl_thread(decl) #endif +/* The __decl_thread_var() statement declares a variable when threads are enabled + * or replaces it with an dummy statement to avoid placing a lone semi-colon. The + * purpose is to condition the presence of some variables or to the fact that + * threads are enabled, without having to enclose them inside an ugly + * #ifdef USE_THREAD/#endif clause. + */ +#ifdef USE_THREAD +#define __decl_thread_var(decl) decl +#else +#define __decl_thread_var(decl) enum { CONCAT(_dummy_var_decl_,__LINE__), } +#endif + /* clang has a __has_feature() macro which reports true/false on a number of * internally supported features. Let's make sure this macro is always defined * and returns zero when not supported. -- 2.39.5