免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
1234
最近访问板块 发新帖
楼主: ypxing

[C] [原创]数组与指针---都是"退化"惹的祸 [复制链接]

论坛徽章:
0
发表于 2009-08-07 22:25 |显示全部楼层

论坛徽章:
8
羊年新春福章
日期:2015-03-19 02:03:312015亚冠之北京国安
日期:2015-06-16 22:04:45程序设计版块每日发帖之星
日期:2015-06-23 22:20:00每日论坛发贴之星
日期:2015-06-23 22:20:002015亚冠之首尔
日期:2015-06-24 19:18:072015亚冠之广州恒大
日期:2015-08-06 10:29:442015亚冠之柏太阳神
日期:2015-11-02 11:21:0515-16赛季CBA联赛之辽宁
日期:2015-12-09 15:05:02
发表于 2015-05-25 16:27 |显示全部楼层
本帖最后由 firocu 于 2015-05-25 17:43 编辑

回复 1# ypxing

4.4 s退化后为什么不可修改
这个问题的答案不能令人信服.
更为合理的答案, 我在c11中看到了, 这是一种语法上的规定:
Except when it is the operand of the sizeof operator, the _Alignof operator, or the
unary & operator, or is a string literal used to initialize an array, an expression that has
type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points
to the initial element of the array object and is not an lvalue.
我觉得c11的文档指的应该是 is not a modifiable lvalue
因为An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).
而数组退化后的pointer在内存是有对应的值.
编译器这个警告, lvalue应该是指 需要一个modifiable lvalue:
error: lvalue required as increment operand

无论如何编译器给出了答案, 因为修改了不是modifiable lvalue的变量.

个人理解..

论坛徽章:
8
羊年新春福章
日期:2015-03-19 02:03:312015亚冠之北京国安
日期:2015-06-16 22:04:45程序设计版块每日发帖之星
日期:2015-06-23 22:20:00每日论坛发贴之星
日期:2015-06-23 22:20:002015亚冠之首尔
日期:2015-06-24 19:18:072015亚冠之广州恒大
日期:2015-08-06 10:29:442015亚冠之柏太阳神
日期:2015-11-02 11:21:0515-16赛季CBA联赛之辽宁
日期:2015-12-09 15:05:02
发表于 2015-05-25 16:28 |显示全部楼层
我靠这都能碰到熟人啊.....回复 31# wenjianhn


   

论坛徽章:
0
发表于 2015-12-25 23:06 |显示全部楼层
值得学习!

论坛徽章:
0
发表于 2015-12-25 23:08 |显示全部楼层
值得学习!

论坛徽章:
6
数据库技术版块每日发帖之星
日期:2015-11-27 06:20:00程序设计版块每日发帖之星
日期:2015-12-01 06:20:00每日论坛发贴之星
日期:2015-12-01 06:20:0015-16赛季CBA联赛之佛山
日期:2017-03-26 23:38:0315-16赛季CBA联赛之江苏
日期:2017-07-17 10:08:4415-16赛季CBA联赛之北京
日期:2018-03-04 17:01:50
发表于 2015-12-26 19:18 |显示全部楼层
还没看懂
,明天继续看

论坛徽章:
0
发表于 2016-06-15 12:57 |显示全部楼层
回复 33# firocu


    Long time no see
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP