免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123
最近访问板块 发新帖
楼主: baozhao
打印 上一主题 下一主题

[C] 指针与地址 (关于标准ISO/IEC 9899:1999(E)的一些问题) [复制链接]

论坛徽章:
0
21 [报告]
发表于 2008-05-29 17:26 |只看该作者

回复 #19 ypxing 的帖子

谢谢你一直热心地答复,主要是这三个问题想了我一天多了,所以搞不清楚心里总是不舒服。这些问题是我看到的一个帖子引发的思考,
http://blog.csdn.net/megaboy/archive/2005/09/17/482782.aspx
该帖的很多观点我不认同,但是却促使我思考了一些问题。

C标准明确规定了object的含义的,见下:

3.14
1 object
region of data storage in the execution environment, the contents of which can represent values

论坛徽章:
0
22 [报告]
发表于 2008-05-29 17:38 |只看该作者

回复 #20 baozhao 的帖子

那篇帖子确实错误很多

另外,LZ再翻翻常量的定义吧

论坛徽章:
0
23 [报告]
发表于 2008-05-29 17:51 |只看该作者

回复 #21 ypxing 的帖子

你是指标准的常量定义吗?见下, integer-constant等具体语法我就不列了。

6.4.4 Constants
Syntax
1 constant:
        integer-constant
        floating-constant
        enumeration-constant
        character-constant

Constraints
2 The value of a constant shall be in the range of representable values for its type.

Semantics
3 Each constant has a type, determined by its form and value, as detailed later.

论坛徽章:
0
24 [报告]
发表于 2008-05-29 18:47 |只看该作者
我的观点仍然是:

&a是常量,它是有类型的,类型为int*

原帖由 baozhao 于 2008-5-29 17:51 发表
你是指标准的常量定义吗?见下, integer-constant等具体语法我就不列了。

6.4.4 Constants
Syntax
1 constant:
        integer-constant
        floating-constant
        enumeration-constant
  ...

论坛徽章:
0
25 [报告]
发表于 2008-05-29 19:27 |只看该作者
原帖由 ypxing 于 2008-5-29 18:47 发表
我的观点仍然是:

&a是常量,它是有类型的,类型为int*




我基本同意,但是问题依然没有解决。

标准的说法是constant address,见下面的原文,

const int a = 3;
3是常量,但a不是。如果constant address和3的性质相同,constant address就是常量,那么就完全没意见。但是constant address如果是和const int相同,那么就不是了。这里我不是很清楚。

标准原文见下:
6.2.4 Storage durations of objects

2 The lifetime of an object is the portion of program execution during which storage is
guaranteed to be reserved for it. An object exists, has a constant address,25) and retains its last-stored value throughout its lifetime.26)

25) The term ‘‘constant address’’ means that two pointers to the object constructed at possibly different times will compare equal. The address may be different during two different executions of the same program.

论坛徽章:
0
26 [报告]
发表于 2008-05-29 21:46 |只看该作者
对问题2,我理解,object指的是“int *a”,整体。

论坛徽章:
0
27 [报告]
发表于 2008-05-30 00:48 |只看该作者
显然,A pointer type describes an object … 一句的描述有其偏颇之处。


谢谢,这也是我私下怀疑的。



另外关于第三个问题,address 我认为依赖context,你能不能评论一下我举出的几个例子。

whyglinux版主我看过你和megaboy的辩论,对你的学识和风度深表钦佩。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP