See the getopt_long() man page:
int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex);
A pair of argc and argv shows one way to tell how many records are in the array (by and large, although with argv[argc] == 0 there is also a watch there). optstring indicates short arguments; longindex is the output parameter. This leaves only the longopts pointer, which means that the function should be able to determine how many records in the array do not support counting (there is no longoptcount argument), so the end of the array is marked with all zero values ββ- a sentinel value.
source share