mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
MINOR: ist: add a macro to ease const array initialization
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.
This commit is contained in:
parent
82967bf9b3
commit
2ba672726c
@ -45,6 +45,9 @@ struct ist {
|
|||||||
size_t len;
|
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.
|
/* makes an ist from a regular zero terminated string. Null has length 0.
|
||||||
* Constants are detected and replaced with constant initializers. Other values
|
* Constants are detected and replaced with constant initializers. Other values
|
||||||
* are measured by hand without strlen() as it's much cheaper and inlinable on
|
* are measured by hand without strlen() as it's much cheaper and inlinable on
|
||||||
|
Loading…
x
Reference in New Issue
Block a user