它是安全的假设,一个指针是在C int的大小? [英] Is it safe to assume that a pointer is the size of an int in C?

查看:184
本文介绍了它是安全的假设,一个指针是在C int的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设计一种新的编程语言,它是安全的假设,一个C int和指针是在机器上同样大小?

In designing a new programming language, is it safe to assume that a C int and a pointer are the same size on the machine?

推荐答案

没有。指针可能比大小的整数更大或更小。如果你需要传递一个指针出于某种原因的整数(如执行整数,而不是指针,算术),他们都保证能够装入的使用intptr_t

No. A pointer may be larger or smaller than an integer in size. If you need to pass a pointer as an integer for some reason (like performing integer, rather than pointer, arithmetic), they are guaranteed to fit into an intptr_t.

它们不能保证装配到一个为size_t作为另一个回答的建议,但在实践中这是不可能的,他们不会,因为最大可寻址尺寸通常等于最大可寻址的地址。

They are not guaranteed to fit into a size_t as suggested in another answer, but in practice it is unlikely that they won't, since the largest addressable size is usually equal to the largest addressable address.

这篇关于它是安全的假设,一个指针是在C int的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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