aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-30 16:31:43 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-30 16:31:43 +0100
commitb31c642e7177cb718579d4f88ed840ba58f7778d (patch)
tree16c8fdf81232d25fe87644faa7e275d25dae29b3
parent5194e53b23f194a4a3193e495a7ff7478d895de4 (diff)
Add the _vtoa() macro
-rw-r--r--cbs.h5
1 files changed, 4 insertions, 1 deletions
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. */