]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ist: add a macro to ease const array initialization
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Sep 2017 13:24:10 +0000 (15:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 21 Sep 2017 13:32:31 +0000 (15:32 +0200)
It's not possible to use strlen() in const arrays even with const
strings, but we can use sizeof-1 via a macro. Let's provide this in
the IST() macro, as it saves the developer from having to count the
characters.

include/common/ist.h

index c9260022b9e271c825a29c94a832d6dc90443260..c57aa8977a45726c1aa88639d28b89dc56cd43d9 100644 (file)
@@ -45,6 +45,9 @@ struct ist {
        size_t len;
 };
 
+/* makes a constant ist from a constant string, for use in array declarations */
+#define IST(str) { .ptr = str "", .len = (sizeof str "") - 1 }
+
 /* makes an ist from a regular zero terminated string. Null has length 0.
  * Constants are detected and replaced with constant initializers. Other values
  * are measured by hand without strlen() as it's much cheaper and inlinable on