简体   繁体   English

使用cygwin在64位Windows上C ++中的int指针大小

[英]Size of int pointer in C++ on 64 bit windows using cygwin

I tried to print the size of int pointer on a 64 bit windows 7 machine. 我试图在64位Windows 7计算机上打印int指针的大小。 I am using cygwin. 我正在使用cygwin。 I expected it to give output 8, but the actual output is 4. 我希望它给出输出8,但实际输出是4。

#include <iostream>
using namespace std;

int main()
{
    cout<< sizeof(int*)<<endl;
    return 0;
}

Possibly related question What the pointer size in 64 bits computer in C++? 可能相关的问题C ++中64位计算机的指针大小是多少?

But it is about compiling as 64 bit project in Visual Studio. 但这是关于在Visual Studio中编译为64位项目。 I couldn't find any such option in cygwin. 我在cygwin中找不到任何这样的选项。 How is this explained? 如何解释?

The "bitness" of the machine or the OS does not matter. 机器或操作系统的“位数”无关紧要。 It makes no difference whatsoever. 没什么区别。

The only thing that matters is what kind of code you asked your compiler to generate. 唯一重要的是您要求编译器生成什么样的代码。 In your experiment you either asked GCC to generate 32-bit code or it defaulted to 32-bit code by itself. 在实验中,您要么要求GCC生成32位代码,要么它本身默认为32位代码。 This is why your pointers are 32-bit wide. 这就是为什么指针为32位宽的原因。

You have to explicitly ask GCC to generate 64-bit code, if you want to see 64-bit pointers. 如果要查看64位指针,则必须明确要求GCC生成64位代码。 Specify -m64 in compiler's command line. 在编译器的命令行中指定-m64

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM