From: Willy Tarreau Date: Wed, 12 Mar 2025 17:08:12 +0000 (+0100) Subject: MINOR: compiler: add a new __decl_thread_var() macro to declare local variables X-Git-Tag: v3.2-dev8~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69ac4cd315;p=thirdparty%2Fhaproxy.git 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. --- 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.