sizeof(size_t)和sizeof(指针) [英] sizeof (size_t) and sizeof (pointer)

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

问题描述

是否必须? :

sizeof(size_t)> = sizeof(指针)

Alex Vinokur

电子邮件:alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978 .html
http://sourceforge.net/users/alexvn

解决方案

Alex Vinokur写道:


是吗不得不? :

sizeof(size_t)> = sizeof(指针)



编号size_t只需要足够大以代表

可以创建的最大对象数。

是指针的大小比@B $ b更大的实现甚至比可以分配的字符数(即

不是全部的指针中的位用于贡献

他的地址)。所有指针

的大小也不一样。


Ron Natalie写道:
< blockquote class =post_quotes>
并非所有指针

都需要相同的大小。



这是真的吗?我认为必须可以将任何

指针转换为void *。如果有不同大小的指针那么

它可能会有问题。


Juha Nieminen写道:


Ron Natalie写道:


>并非所有指针
都需要相同的大小。



这是真的吗?我认为必须可以将任何

指针转换为void *。如果有不同大小的指针

那么它可能会有问题。



如果void *至少与其中最大的一样大,该怎么办?如果

尺寸确实不同,那就没有意义,不是吗?


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问


Does it have to be? :
sizeof (size_t) >= sizeof (pointer)

Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

解决方案

Alex Vinokur wrote:

Does it have to be? :
sizeof (size_t) >= sizeof (pointer)

No. size_t only has to be big enough to represent the
maximum number of objects that could be created. There
are implementations where the sizeof the pointer is bigger
than even the number of chars that could be allocated (i.e,
not all the bits in the pointer were used to contribute
tot he address). It''s also not the case that all pointers
need to be the same size.


Ron Natalie wrote:

It''s also not the case that all pointers
need to be the same size.

Is that really so? I thought that it must be possible to cast any
pointer to and from a void*. If there were different-sized pointers then
it could be rather problematic.


Juha Nieminen wrote:

Ron Natalie wrote:

>It''s also not the case that all pointers
need to be the same size.


Is that really so? I thought that it must be possible to cast any
pointer to and from a void*. If there were different-sized pointers
then it could be rather problematic.

What if void* is at least as large as the largest of them? If the
sizes do differ, it would makes sense, no?

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


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

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