Mark Summerfield
2024-08-28 07:06:43 UTC
I'm using getopt_long() to process a command line.
So after a typical call I might have:
argv == {"./efind", "-D", "-x", "one", "two", "three", "four"}
optind == 3
What I'd like to do (without copying or mallocing and without using a VLA)
is to get a pointer to a slice of argv, specifically,
{"one", "two", "three", "four"}.
In Python terms argv[optind:argc].
Is this possible in C?
At the moment I store argv, optind, and argc and handle the slice using a loop:
if (config->optind < config->argc)
for (int i = config->optind; i < config.argc; ++i)
process(config->argv[i]);
This works fine, so really I'm just wondering if there's a nicer way.
So after a typical call I might have:
argv == {"./efind", "-D", "-x", "one", "two", "three", "four"}
optind == 3
What I'd like to do (without copying or mallocing and without using a VLA)
is to get a pointer to a slice of argv, specifically,
{"one", "two", "three", "four"}.
In Python terms argv[optind:argc].
Is this possible in C?
At the moment I store argv, optind, and argc and handle the slice using a loop:
if (config->optind < config->argc)
for (int i = config->optind; i < config.argc; ++i)
process(config->argv[i]);
This works fine, so really I'm just wondering if there's a nicer way.