]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compiler: add more macros to detect macro definitions
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Apr 2025 06:56:56 +0000 (08:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Apr 2025 18:21:06 +0000 (20:21 +0200)
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.

include/haproxy/compiler.h

index 7d42375b336d934b76ee1b3d437196bbef0b1d99..80d9be77254ae5cf2294783315053c2d6e681481 100644 (file)
 #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