int command(int argc, const char*const* argv);
in this line
what's the mean of : char* const* argv ?
i don't understand it
Thank you for explaining it for me!
int command(int argc, const char*const* argv);
in this line
what's the mean of : char* const* argv ?
i don't understand it
Thank you for explaining it for me!
The parameter argv is meant to be an array of strings.
There is a reason for the const modifier, as the argv pointer wont be reassigned, the elements will have to be accessed by subscript. This makes it safe for the caller to dynamically allocate argv, pass it into command(), and free it later. Otherwise, if you point a pointer elsewhere before it is freed, then you've leaked the memory that it used to point to.
So for example an expression like this
argv[counter]
is OK, but an expression like this
*argv++
is not.
Of course, you can choose not to use const and just use the subscript notation, but the compiler will not enforce its use.
char* const* argv creates two levels of indirection - the first level is a constant pointer to char, and the second level is a pointer to the constant pointer.
Yes, const char * is the string part, and const *argv would be the dynamically allocated array part.
Whoops! and thanks for pointing that out whiteflags. Need to patch my post as I totally missed the first const in the declaration.
const char* const* argv creates two levels of indirection - first level is a const pointer to a const char, and second level is a pointer to the const pointer.