C语言中的const char,C语言中为什么不能把char**赋给const char**

标签: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;

(......省略......)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值