Proposal: fix for getOpt (missing feature)

Jaap Weel jaapweel at
Tue Jun 26 04:16:34 EDT 2007

> It is the behaviour of GNU GetOpt, which is very widely used and
> understood.

No, it isn't. At least, it's not the default. The GNU libc manual
encourages the use of getopt_long(). It also provides an alternative
called getopt_long_only() for programs that want to be backward

Here's the relevant bit from the libc manual:

     Since long option names were used before before the `getopt_long'
  options was invented there are program interfaces which require
  programs to recognize options like `-option value' instead of
  `--option value'.  To enable these programs to use the GNU getopt
  functionality there is one more function available.

   -- Function: int getopt_long_only (int ARGC, char *const *ARGV,
            const char *SHORTOPTS, const struct option *LONGOPTS, int

       The `getopt_long_only' function is equivalent to the
       `getopt_long' function but it allows to specify the user of the
       application to pass long options with only `-' instead of `--'.
       The `--' prefix is still recognized but instead of looking
       through the short options if a `-' is seen it is first tried
       whether this parameter names a long option.  If not, it is
       parsed as a short option.

       Assuming `getopt_long_only' is used starting an application

              app -foo

       the `getopt_long_only' will first look for a long option named
       `foo'.  If this is not found, the short options `f', `o', and
       again `o' are recognized.



More information about the Libraries mailing list