【发布时间】:2012-12-06 15:08:47
【问题描述】:
可能重复:
why isnt it legal to convert (pointer to pointer to non-const) to a (pointer to pointer to a const)
为什么在调用 foo 时会收到警告 (gcc 42.2)?
void foo(const char **str)
{
(*str)++;
}
(...)
char **str;
foo(str);
(...)
我明白为什么我们不能用const char ** 调用除char ** 之外的函数,但相反的情况对我来说似乎没问题,那么为什么会出现以下警告?
warning: passing argument 1 of 'foo' from incompatible pointer type
【问题讨论】:
-
你使用了哪些编译标签?
-
我认为这是不合法的,尽管有这样一个不兼容的分配你可以在某些情况下颠覆 const 而无需强制转换。