2

Possible Duplicate:
Double pointer const-correctness warnings in C

Look at the table here: http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html

We see that the following is invalid in C:

void f(const char * const argv[])
{
    (void)argv;
}

int main(int argc, char *argv[])
{
    (void)argc;
    f(argv);
    return 0;
}

test.c: In function 'main':
test.c:9: warning: passing argument 1 of 'f' from incompatible pointer type
test.c:1: note: expected 'const char * const*' but argument is of type 'char **'

Why is this invalid? It seems to me that const char * const argv[] is just "more constant" than char * argv [], (and it's allowed in C++) so why is it invalid in C?

Community
  • 1
  • 1
Rodrigo Queiro
  • 1,324
  • 8
  • 15
  • Did you read this answer ? http://stackoverflow.com/a/766406/1126268 – md5 Jul 23 '12 at 12:24
  • @Kirilenko I think they're all answering this question: http://www.parashift.com/c++-faq/constptrptr-conversion.html (char ** -> const char **), but my question concerns (char ** -> const char **). The former in invalid in C & C++, but the latter is only invalid in C as far as I can tell. – Rodrigo Queiro Jul 23 '12 at 12:59
  • ecatmur: it is a duplicate of that. – Rodrigo Queiro Jul 23 '12 at 13:10

0 Answers0