So, man page says getopt()
takes char * const argv[]
, which is an array of constant pointers to char, as far as I understand. At the same time, getopt()
permutes argv
, so that eventually all non-options are at the end of the array.
I find it very confusing, because it now has to swap strings character by character instead of just swapping pointers, or so. Why doesn't it take just char * argv[]
?
From the man page for Linux:
Conforming To
POSIX.2 and POSIX.1-2001, provided the environment variablePOSIXLY_CORRECT
is set. Otherwise, the elements ofargv
aren't reallyconst
, because we permute them. We pretend they'reconst
in the prototype to be compatible with other systems.
So you can omit the const
qualifier on Linux.