Question

How do you specify that a short-option can accept an optional_argument in getopt.

As far as I can tell, GNU's getopt library for C only supports required-arguments for short-options by adding a : after a given option.

Example:

static const char* short_opts = "s:evlh";

How do I specify that s accepts arguments, but doesn't require them?

I know how to do this in Ruby, but I've never been able to figure out how to do it in C--I've reviewed the GNU documentation for getopt several times, but to no avail.

Était-ce utile?

La solution

From the documentation:

If an option character is followed by two colons (‘::’), its argument is optional; this is a GNU extension.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top