getopt
Karl Heuer
karl at haddock.ima.isc.com
Fri Jun 16 12:29:01 AEST 1989
In article <782 at crdgw1.crd.ge.com> davidsen at crdos1.UUCP (bill davidsen) writes:
>I have a program which needs an option which may have either a default
>value or a specific value. ie. "-c" or "-c4" would be typical. I would
>like to use getopt to read the values.
This doesn't fit the Official Arg Passing Style, so even if you use a hook a
kludge into getopt(), it isn't guaranteed to always work.
> In the meantime, I took a P.D. version and added another option
>qualifier, #, indicating an optional numeric argument.
Why restrict it to numeric? I use optional non-numeric arguments all the
time. If you're going to add the optional-argument hack, you might as well
let it return (in optarg) whatever string immediately followed the keyletter,
including the empty string in the case of "-c". (No reason for it ever to
return NULL; that would make an unnecessary special case.)
>Since the character # could be an option in some software, my new version is
>not a superset.
"-#" is a not uncommon debugging option. I think ";" is a better choice,
since it does half of what ":" does%, and because I don't know of any code
that uses "-;" as an option.
Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
________
% This pun works only if you pronounce them as "semicolon" and "colon".
More information about the Comp.lang.c
mailing list