c++ - sizeof(int) 是否总是等于 sizeof(void*)

标签 c++

<分区>

Possible Duplicate:
sizeof (int) == sizeof (void*)?

我想知道是否可以保证,在 32 位和 64 位系统中,sizeof(int) 总是等于 sizeof(void*) (即分别为 32 位和 64 位)。

此外,我需要知道是否始终保证 long int 可以容纳 intvoid* 的位一起,例如

long int lint = (((int)integer)<<sizeof(int)) | (void*)ptr;

最佳答案

I was wondering whether it is guaranteed that, in both 32-bit and 64-bit systems, sizeof(int) is always equal to sizeof(void*)

没有。

I need to know whether it is always guaranteed that a long int can accommodate the bits of an int and a void* together

没有。一个快速证明是在 许多 现代平台上考虑 sizeof(long int) == sizeof(int),可能包括您正在使用的平台。

更重要的问题是为什么您认为您“需要知道”这个;事实上,您问这样的问题让我担心您的代码可能会……摇摆不定。

关于c++ - sizeof(int) 是否总是等于 sizeof(void*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9244413/

相关文章:

javascript - 使用 firebreath 插件打开文件夹对话框并异步返回文件夹选择,这样 java 脚本就不会被阻止

c++ - 用Qt序列化,不用Qt反序列化?

c++ - Qt - QTcpSocekt 无法检测到连接丢失

c++ - 未解析的外部符号 _main 在函数 ___tmainCRTStartup 中引用

C++ 数组 "Cut"算法

c++ - 为什么 std::async 比简单的分离线程慢?

C++ union 内部

c++ - AMQP C++ 实现

c++ - 矩阵模式。稀疏行运算符*(矩阵, vector )

c++ - 在 Rcpp (Armadillo) 函数中使用数字序列作为默认参数