Maury Markowitz
Maury Markowitz

Reputation: 9279

getopt_long confusion, flag setting with single-char switches

I'm parsing command line options using getopt_long based on the example from the man page. That example does something a bit sneaky, it includes two flag-setting options in long_options but does not list those in the short form parameter string in getopt_long.

Poking about, this answer clarifies what happens in this case, if they enter the short-form it does not set the flag. And leads to my question: If you have a flag-setting switch, and you want to have both long and short forms for that switch on the command line...

  1. Did I miss an option in the short-form string to set flags, sort of like how : works for indicating a parameter follows? Like "v?1" or something?

  2. Failing that, is it best-practices to not do it in the long-form as well, and just return 'v'? Or would "the average code" use the flag-set and have separate code in the switch?

I'd like my code to be "as standard as possible", whatever that means, which is my I'm curious about (2).

Upvotes: 0

Views: 117

Answers (0)

Related Questions