I'm trying to write a function to parse command line arguments. This is the function declaration:
void parse(int, char const **);
Just in case, I have also tried (const char)**
, const char **
, and cchar **
using a typedef const char cchar
. However, all of these (as expected, since they should all be identical) result in an error if I pass a char **
into the function, as in:
void main(int argc, char **argv) {
parse(argc, argv);
The error I get from GNU's compiler is error: invalid conversion from 'char**' to 'const char**'
and the one from Clang is candidate function not viable: no known conversion from 'char **' to 'const char **' for 2nd argument
.
I have seen such solutions suggested as declaring a pointer to a const pointer to char (const char * const *
), but I don't want either pointer to be const because I want to be able to modify the pointer so I can iterate over an argument using for(; **argv; ++*argv)
. How can I declare a "non-const pointer to non-const pointer to const char"?