From b31c642e7177cb718579d4f88ed840ba58f7778d Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 30 Dec 2023 16:31:43 +0100 Subject: Add the _vtoa() macro --- cbs.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cbs.h b/cbs.h index 2729574..f47d237 100644 --- a/cbs.h +++ b/cbs.h @@ -102,6 +102,9 @@ # define _Nullable #endif +/* Convert the given variadic arguments to a string array */ +#define _vtoa(...) ((char *[]){__VA_ARGS__}) + /* Internal global versions of argc and argv, so our functions and macros can access them from anywhere. */ static int _cbs_argc; @@ -152,7 +155,7 @@ typedef struct { the given command. */ static void cmdaddv(cmd_t *, char **p, size_t n); #define cmdadd(cmd, ...) \ - cmdaddv(cmd, ((char *[]){__VA_ARGS__}), lengthof(((char *[]){__VA_ARGS__}))) + cmdaddv(cmd, _vtoa(__VA_ARGS__), lengthof(_vtoa(__VA_ARGS__))) /* Clear (but not free) the command c. Useful for reusing the same command struct to minimize allocations. */ -- cgit v1.2.3