From: Willy Tarreau Date: Mon, 28 Apr 2025 06:56:56 +0000 (+0200) Subject: MINOR: compiler: add more macros to detect macro definitions X-Git-Tag: v3.2-dev13~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ac280f2a7bc36d5c288844b920c9ee8e1d1a6eb;p=thirdparty%2Fhaproxy.git MINOR: compiler: add more macros to detect macro definitions We add __equals_0(NAME) which is only true if NAME is defined as zero, and __def_as_empty(NAME) which is only true if NAME is defined as an empty string. --- diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index 7d42375b3..80d9be772 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -55,6 +55,24 @@ #define ___equals_1(x) ____equals_1(comma_for_one ## x 1) #define __equals_1(x) ___equals_1(x) +/* same but checks if defined as zero, useful to distinguish between -DFOO and + * -DFOO=0. + */ +#define comma_for_zero0 , +#define _____equals_0(x, y, ...) (y) +#define ____equals_0(x, ...) _____equals_0(x, 0) +#define ___equals_0(x) ____equals_0(comma_for_zero ## x 1) +#define __equals_0(x) ___equals_0(x) + +/* same but checks if defined as empty, useful to distinguish between -DFOO= and + * -DFOO=anything. + */ +#define comma_for_empty , +#define _____def_as_empty(x, y, ...) (y) +#define ____def_as_empty(x, ...) _____def_as_empty(x, 0) +#define ___def_as_empty(x) ____def_as_empty(comma_for_empty ## x 1) +#define __def_as_empty(x) ___def_as_empty(x) + /* gcc 5 and clang 3 brought __has_attribute(), which is not well documented in * the case of gcc, but is convenient since handled at the preprocessor level. * In both cases it's possible to test for __has_attribute() using ifdef. When