Bug#68923: Getopt long options example needs rewriting
Package: glibc-doc
Version: 2.1.3-10
Severity: wishlist
The example givin in the '(libc)Getopt Long Options' node is messed up,
as it looks unlike any GNU program I have seen.
It should use NULL instead of 0 as a pointer and should use the
constants no_argument, required_argument and optional_argument instead
of 0 and 1 in the second element in these lists below.
And the fourth place is typically the short option.
It says now
static struct option long_options[] =
{
/* These options set a flag. */
{"verbose", 0, &verbose_flag, 1},
{"brief", 0, &verbose_flag, 0},
/* These options don't set a flag.
We distinguish them by their indices. */
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
but should be like
{"delete", required_argument, NULL, 'd'},
{"create", no_argument, NULL, 'c'},
{"file", required_argument, NULL, 'f'},
{NULL, 0, NULL, 0}
Reply to: