For example the option array is:
static struct option const long_options[] =
{
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
Is it for padding?
Look at the man page for getopt_long()
:
int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex);
The argc
and argv
pair show one way to say how many entries there are in an array (by explicit count, though since argv[argc] == 0
, there is also a sentinel there). The optstring
indicates short arguments; the longindex
is an output parameter. That leaves only the pointer longopts
which means that the function must be able to tell how many entries are in the array without any supporting count (there is no longoptcount
argument), so the end of the array is marked by all values zero - a sentinel value.
It's a 'sentinel' so the code processing the array knows when it's gotten to the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With