【发布时间】:2010-08-16 18:14:50
【问题描述】:
可能重复:
Why can’t I convert ‘char**’ to a ‘const char* const*’ in C?
我很好奇,为什么我不能将char ** 传递给const char ** 函数?虽然可以将 char * 传递给 const char * 函数,但使用双指针似乎不太好。我认为添加 constness 总是可以的(但不能删除 constness),但现在看来我错了。
Gcc 编译器给了我错误:
note: expected ‘const char **’ but argument is of type ‘char **’
这里是sn-p的代码:
int f(const char **a) { }
int main() {
char *a;
f(&a);
}
有什么想法吗?
【问题讨论】:
-
顺便说一句,对于投票结束的人:这不是 stackoverflow.com/questions/78125/… 的完全重复,因为它专门针对
const char* const*。 (但是,其中一些答案是相关的。)