i disagree with the sentiment and preferences expressed in your comment. the code on display is at the sweet spot of complexity
given the scope of task at hand. your preferences might lead to code with lower complexity of any given expression, but there would be a higher number of expressions, higher number of statements, and higher number of names. that would mean
higher complexity of the full code. should we ban multiplication on the basis that X times Y is the same as X plus X plus X...?
> Why pre-inc/decrement?
as opposed to what? nothing? clearly, the code needs to advance the iterators before dereferencing.
> Why the +1 on the for?
because it's interested in the option name as opposed to the leading dash: argv[0][0] is '-' (see the while above), the switch is looking at argv[0][1].
> Did he actually get the precedence of the operators correct?
not sure what this is about, the only involved expression has explicit parentheses (out of necessity).
> Okay, it looks like argc and argv will be mangled if you actually want to do anything else with them.
yes... and? mutating a local int and a local pointer is bad? how would you go about this without mutating an iterator?
> I see comparing to '\0' with no count limit--is there a buffer overrun lurking here?
nope, it's an array of null-terminated strings.
> Does that error handling actually work--that loop can't exit with that condition unless the second clause does something.
i do not understand what you're pointing at here.
> I'd assign argc and argv to something else so if I need them later for something they are in their original state.
consider they're already local names, and YAGNI. do alias them if you need them later, not because you might one day.
> I'd give myself a variable that points to each individual argv on each iteration, and I'd call it something.
you would give yourself a possible bug and an obligation to keep the two things in sync.
> I'd make the error handling more explicit so if I had to add another case later I wouldn't have to rack my brain about whether the error gets handled.
what is more explicit than
printf("Illegal option %c\n", *s);
?
i'd really love to see your preferred version of the snippet from TFA. i posit it'd be two to three times as long, and its total complexity would be similarly increased.