0

I tried to print the size of int pointer on a 64 bit windows 7 machine. I am using cygwin. I expected it to give output 8, but the actual output is 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++?

But it is about compiling as 64 bit project in Visual Studio. I couldn't find any such option in cygwin. How is this explained?

Community
  • 1
  • 1
kalyan
  • 23
  • 7
  • Yes, the setup I downloaded was marked x86_64. I will reinstall and verify just to be sure – kalyan Aug 09 '14 at 07:09
  • reinstall won't change a thing (does it ever? :]): you have to specify the correct compiler on the commandline or makefile, and you probably have both versions installed - show us the command you use to build the code – stijn Aug 09 '14 at 07:13
  • What does `gcc -v 2>&1 | grep Target` say? Maybe try using the `-m64` option on the compiler command line to force a 64-bit build. – Michael Burr Aug 09 '14 at 07:14
  • The output is mingw32. It seems I configured something wrong while installing cygwin. Also, -m64 option says " sorry, unimplemented: 64-bit mode not compiled in" – kalyan Aug 09 '14 at 07:25
  • I guess I had mingw32 installed previously with its path variable set. I removed cygwin and mingw32 and reinstalled cygwin. Now Target is "x86_64-pc-cygwin" and the issue is resolved – kalyan Aug 09 '14 at 09:06

1 Answers1

2

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. This is why your pointers are 32-bit wide.

You have to explicitly ask GCC to generate 64-bit code, if you want to see 64-bit pointers. Specify -m64 in compiler's command line.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765