地址和整数 [英] addresses and integers

查看:125
本文介绍了地址和整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读标准中的地址

基本上不能解释为整数。

如果可以的话,它是实现定义的

行为。但是,如果他们不能被视为

就任何意义上的整数而言便携性

去了什么,那么,应该想到地址

由?

解决方案

j0mbolar写道:


我读过地址标准基本上不能解释为整数。
如果可以的话,它就是实现定义的行为。但是,如果就可移植性而言,它们在任何意义上都不能被视为整数,那么,人们应该如何看待由

组成的地址?




基础和补偿。


-

pete


2004年8月30日星期一00:21:31 GMT,pete< pf ***** @ mindspring.com>在comp.lang.c写了


j0mbolar写道:


我读过地址标准基本上不能解释为整数。
如果可以的话,它就是实现定义的行为。但是,如果就可移植性而言,它们在任何意义上都不能被视为整数,那么,人们应该如何看待由

组成的地址?

<基础和抵消。




你能为你明显的b / b
荒谬的断言提供任何理由吗? />

-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top。 html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~一... FAQ-A cllc.html


2004年8月29日16:57:46 -0700, j0 ****** @ engineer.com (j0mbolar)在comp.lang.c中写了


我已阅读标准中的地址
基本上不能被解释为整数。


这是正确的,地址是常数。事实上,它们是rvalues,而不是
lvalues。函数也不能被解释为整数,也不能解释为
结构。它是什么?

如果可以,它是实现定义的行为。但是,如果就可移植性而言,它们在任何意义上都不能被视为整数,那么,人们应该如何看待由

组成的地址?




C中的地址不是组合的任何事情。它们没有定义

内部结构,就像浮点类型没有一样。


要求地址可以用字符串表示

的二进制数字,因为一个地址可以存储在一个指针对象

的适当类型中,该指针对象可以作为一个数组进行检查

无符号字符,并且在这种检查时,指针对象必须包含位而不包含位。


这与检查包含的位相同数组

无符号字符也适用于浮点类型,但

这些位的解释或含义完全没有指定

标准。


标准确实要求如果一个实现提供足够宽的

整数类型来包含一个指针,那么赋值为一个转换
$ b指向该整数类型的指针值的$ b,然后再使用强制转换为
o riginal指针类型将产生相同的指针。 C99甚至

定义了用于这种类型的typedef,intptr_t和uintptr_t,

虽然它们是可选的。我认为最好是

标准需要typedef,如果存在这样的整数类型,

方式它需要精确的宽度定义。


标准不要求或保证你可以做任何事情

对于这种类型的转换指针很有用,除了转换

它回来。特别是,不能保证:


char name [] =" name";

char * n = name;

uintptr_t up = n;

++ up;

n = up;


.... n now points名称中的a,或者具有任何有效值。


地址完全没有可移植性,即使在

执行之间也是如此相同的程序。


您认为他们应该拥有哪些便携性?为什么?为什么

你认为你需要考虑它们或将它们视为整数?什么

你认为你需要做的地址不能用指针合法地完成
吗?


-

Jack Klein

主页: http:// JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com/c++ -faq-lite /

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


-

Jack Klein

主页: http://JK-Technology.Com



comp.lang.c的常见问题解答 http://www.eskimo.com/~scs/ C-faq / top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++ http://www.contrib.andrew.cmu.edu /〜a...FAQ-acllc.html


I''ve read in the standard that addresses
basically can''t be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can''t be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?

解决方案

j0mbolar wrote:


I''ve read in the standard that addresses
basically can''t be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can''t be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?



Bases and offsets.

--
pete


On Mon, 30 Aug 2004 00:21:31 GMT, pete <pf*****@mindspring.com> wrote
in comp.lang.c:

j0mbolar wrote:


I''ve read in the standard that addresses
basically can''t be interpreted as integers.
If they can, it is implementation defined
behavior. However, if they can''t be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?



Bases and offsets.



Can you provide any justification at all for your apparently
ridiculous assertion?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


On 29 Aug 2004 16:57:46 -0700, j0******@engineer.com (j0mbolar) wrote
in comp.lang.c:

I''ve read in the standard that addresses
basically can''t be interpreted as integers.
That''s right, addresses are constants. In fact, they are rvalues, not
lvalues. Functions can''t be interpreted as integers either, nor can
structures. What of it?
If they can, it is implementation defined
behavior. However, if they can''t be viewed
as integers in any sense as far as portability
goes, what then, should one think of addresses
being composed of?



Addresses in C are not "composed" of anything. They have no defined
inner structure, just as the floating point types do not.

There is a requirement that an address can be represented in a string
of binary digits, because an address can be stored in a pointer object
of appropriate type, that pointer object can be inspected as an array
of unsigned chars, and upon such inspection the pointer object must
contain bits and nothing but bits.

This same possibility of inspection as the bits contained in an array
of unsigned characters also applies to the floating point types, but
the interpretation or meaning of those bits is totally unspecified by
the standard.

The standard does require that if an implementation provides an
integer type wide enough to contain a pointer, assignment with a cast
of a pointer value to that integer type and back again with a cast to
the original pointer type will yield an identical pointer. C99 even
defines typedef to be used for such a type, intptr_t and uintptr_t,
although they are optional. I think it would have been preferable for
the standard require the typedefs if such an integer type existed, the
way it requires the exact width definitions.

The standard does not require or guarantee that you can do anything
useful with a converted pointer in such a type, other than converting
it back. In particular, there is no guarantee that:

char name [] = "name";
char *n = name;
uintptr_t up = n;
++up;
n = up;

....n now points to the ''a'' in name, or has any valid value at all.

Addresses have absolutely no portability at all, even between
executions of the same program.

What portability do you think they should have, and why? And why do
you think you need to think of them or treat them as integers? What
is it that you think you need to do with addresses that cannot
legitimately be done with pointers?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


这篇关于地址和整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆