Some but not all versions of getopt
allow you to indicate that an argument is optional by putting two colons after the relevant option character.
Wanting an optional argument to an option is a sign that your program is complicated enough that you should consider supporting long option names. Unfortunately there is no standard function to do this, but GNU libc has two: getopt_long
and the even more powerful argp
. If your software is GPL-compatible, you can get either of them from gnulib and then you don't depend on glibc.