I'm wondering if command line parameters are always null terminated. Google seems to say yes, and compiling on GCC indicates this is the case, but can I guarantee this to always be true?
int main(int argc, char** argv)
{
char *p;
for(int cnt=1; cnt < argc; ++cnt)
{
p = argv[cnt];
printf("%d = [%s]\n", cnt, p);
}
return 0;
}
$ MyProgram -arg1 -arg2 -arg3
1 = -arg1
2 = -arg2
3 = -arg3
char* argv[]
is not a 2D array; it's an array of pointers. (Surely in a real 2D array, each string would have to be the same length, so we wouldn't need a terminator?) The pointed-to objects do not have to be adjacent to each other. That is: here, it is not required that the address pointed to by each successive pointer must be 1 byte after the NUL terminating the previously numbered argument. – Ginsburg