0

why the program gived a warning about foo's argument?

void foo(const char **p)
{ 

}

int main(int argc, char **argv)
{
      foo(argv);          //problem is here
      return 0;
}

MinGW gives a waring like this:

warning : passing argument 1 of 'foo' from incompatible pointer type [enabled by default]
Nibnat
  • 13
  • 2

1 Answers1

0

Function foo() is expecting const char ** but argv is char **.

Your code can be written in one of 3 ways.

Change the definition of foo() to expect char ** instead of const char **.

void foo(char **p)

or

Change argv in main() to const char **.

int main(int argc, const char **argv)

or

Cast argv as (const char **) when passed to foo().

foo((const char **)argv);
alvits
  • 6,550
  • 1
  • 28
  • 28
  • this is a question I found in a website and it says:sending a normal pointer to a function requiring const pointer does not give any warning,so I thought there exits a prolbem which I don't know~ – Nibnat Dec 16 '13 at 04:24