指针的大小 [英] Sizeof for pointers

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

问题描述




我只是想确认一个指针的sizeof总是在机器上返回

相同的值。

如果有人回复,我将不胜感激。


谢谢。

解决方案

Avinash说:





我只是想确认一个指针的sizeof总是返回

机器上的相同值。



它没有。我有一台机器,上面有不同的编译器,

,它使用不同大小的同一种指针。


但是在给定的机器上,使用给定的编译器给定版本的给定

选项,我认为指针的大小不会改变,这可能是安全的。可以肯定的是,在程序运行中,

指针大小是固定的。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。


Richard Heathfield写道:


它没有。我有一台机器,上面有不同的编译器,

,它使用不同大小的同一种指针。


但是在给定的机器上,使用给定的编译器给定版本的给定

选项,我认为指针的大小不会改变,这可能是安全的。可以肯定地说,在程序运行中,

指针大小是固定的。



只是为了强调理查德的观点在这种情况下,特定

类型指针的大小在这些条件下不会改变;它可能是

,比如说,一个无效指针和一个函数指针可以有不同的

大小。


"阿维纳什" < av ****** @ gmail.comwrites:


我只是想确认一个指针的sizeof总是返回

机器上的价值相同。

如果有人对此做出回应,我将不胜感激。



与什么值相同?


在许多实现中,所有指针都是相同的大小,但它是'不是

由语言保证。您可以假设sizeof将

在同一实现中为相同类型产生相同的值

(某些编译器选项可能实际上导致它变为不同的

实施)。除此之外,很少有理由编写代码

,假设所有指针都具有相同的大小。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/~ kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Hi,

I just wanted to confirm that sizeof for a pointer always returns the
same value on a machine.
I would appreciate if somebody would respond to this.

Thanks.

解决方案

Avinash said:

Hi,

I just wanted to confirm that sizeof for a pointer always returns the
same value on a machine.

It doesn''t. I have a machine right here with different compilers on it,
which use different sizes for the same kind of pointer.

But on a given machine, using a given version of a given compiler with given
options, I think it''s probably safe to say that the size of a pointer won''t
change. What is certainly safe to say is that, within a program run,
pointer size is fixed.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


Richard Heathfield wrote:

It doesn''t. I have a machine right here with different compilers on it,
which use different sizes for the same kind of pointer.

But on a given machine, using a given version of a given compiler with given
options, I think it''s probably safe to say that the size of a pointer won''t
change. What is certainly safe to say is that, within a program run,
pointer size is fixed.

Just to emphasize a point Richard makes here, the size of a particular
type of pointer won''t change under those conditions; it''s possible
that, say, a void pointer and a function pointer can have different
sizes.


"Avinash" <av******@gmail.comwrites:

I just wanted to confirm that sizeof for a pointer always returns the
same value on a machine.
I would appreciate if somebody would respond to this.

The same value as what?

On many implementations, all pointers are the same size, but it''s not
guaranteed by the language. You can probably assume that sizeof will
yield the same value for the same type in the same implementation
(some compiler options may in effect cause it to be a different
implementation). Beyond that, there''s seldom a reason to write code
that assumes that all pointers have the same size.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


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

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