Here I wrote a little app which is able to read command line arguments
int main (int argc, const char * argv[])
{
int c;
while ((c = getopt (argc, argv, "Il:o:vh?")) != -1)
{
switch(c)
{
case 'I':
printf("I");
break;
}
}
return 0;
}
The problem is that when I try to compile it the compiler prints
warning: passing argument 2 of ‘getopt’ from incompatible pointer type
and program crash.
What I miss ?
The
argvargument tomainshould have typechar *[], notconst char *[]so that it can be converted to thechar *const []thatgetoptexpects. In fact,char *[]or equivalent is mandated by the C standard for hosted implementations.