标签:c 指针
这是我在知乎回答的一个问题.
这个问题是C中的一个深坑,首先说结论:
char ** 和 const char ** 是两个不相容(incompatible)的类型,可以理解为不能直接赋值
在C11的6.5.2.2 Function calls中有如下内容
Each argument shall have a type such that its value may be assigned to an object with the unqualified version of the type of its corresponding parameter.
翻译:每个实参都应该具有自己的类型,这样它的值就可以赋给对应非完全限定版本形参类型的对象
也就是说:参数传递的过程和赋值是类似的.
再看6.5.16.1 Simple assignment中的约束条件
Constraints
1 One of the following shall hold:112)
(......省略......)
-- the left operand has atomic, qualified, or unqualified pointer type, and (considering
the type the left operand would have after lvalue conversion) both operands are
pointers to qualified or unqualified versions of compatible types, and the type pointed
to by the left has all the qualifiers of the type pointed to by the right;
(......省略......)