2

可能重复:
C 中的双指针 const 正确性警告

看看这里的表格:http: //pubs.opengroup.org/onlinepubs/009695399/functions/exec.html

我们看到以下内容在 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 **'

为什么这是无效的?在我看来,这const char * const argv[]只是比char * argv [],“更恒定”(并且在 C++ 中是允许的),那么为什么它在 C 中无效?

4

0 回答 0