如果指针只是保存地址(4 字节 - 32 位)的整数,那么它们如何将额外地址存储在 64 位内存中?
If pointers are just integers that hold an address (4 bytes - 32 bits), how do they store the extra addresses in 64-bit memory?
在 C++ 程序中使用 sizeof() 函数时,我看过的指针似乎都是 return 4 字节的大小。我在网上看到指针只是整数内存地址。这在 64 位体系结构中有何意义,因为 64 位体系结构可能具有无法以 4 字节访问的内存地址?
If pointers are just integers that hold an address (4 bytes - 32 bits), how do they store the extra addresses in 64-bit memory?
32 位指针不能 存储 64 位地址。这就是为什么指针在 64 位系统上是 64 位的原因。
大多数现代 64 位操作系统都支持 32 位模式以实现向后兼容性。如果你sizeof(void*) == 4
,那么你的操作系统可能是针对32位平台的,所以你的程序会运行在32位模式下。
查看您的编译器文档,了解如何针对操作系统的 64 位平台。之后,您应该注意到 sizeof(void*) == 8
.
在 C++ 程序中使用 sizeof() 函数时,我看过的指针似乎都是 return 4 字节的大小。我在网上看到指针只是整数内存地址。这在 64 位体系结构中有何意义,因为 64 位体系结构可能具有无法以 4 字节访问的内存地址?
If pointers are just integers that hold an address (4 bytes - 32 bits), how do they store the extra addresses in 64-bit memory?
32 位指针不能 存储 64 位地址。这就是为什么指针在 64 位系统上是 64 位的原因。
大多数现代 64 位操作系统都支持 32 位模式以实现向后兼容性。如果你sizeof(void*) == 4
,那么你的操作系统可能是针对32位平台的,所以你的程序会运行在32位模式下。
查看您的编译器文档,了解如何针对操作系统的 64 位平台。之后,您应该注意到 sizeof(void*) == 8
.