farhangdon
farhangdon

Reputation: 2003

I have 64 bit OS (Win 7) but when I check the sizeof(pointer) it says 4 byte . Should it not be 8 byte for 64 bit OS

I have read many posts that for a 16 bit system the sizeof(ptr) should be 2 byte , for a 32 bit system sizeof(ptr) = 4 byte and for a 64 bit system sizeof(ptr) = 8 byte and it makes sense also but on my machine which has a 64 bit OS (4 GB RAM) its says the sizeof(ptr) = 4 byte . Can someone explains it to me. Thanks

Upvotes: 1

Views: 119

Answers (2)

jmstoker
jmstoker

Reputation: 3475

You mentioned in the comments you're using Visual Studio. To setup this compiler to build 64bit solutions the following will work for Visual Studio 2010, 2012, and 2013. The steps below were taken from the Microsoft MSDN site.

  1. Right click on your solution in the solution explorer.
  2. Choose properties.
  3. Click the Configuration Manager... in the upper right corner.
  4. Click the drop down arrow under Active solution configuration
  5. Choose New and enter a name for this configuration. i.e. Debug64 or Release64
  6. Click the drop down arrow under Copy settings from and Choose Win32. Copying from Win32 will automatically update multiple settings to 64bit.
  7. Click Ok.
  8. Under Active solution platform choose New
  9. Under the platform should be an option for x64. Select this and click Ok.
  10. Click Close.

You should now be building for the x64 platform and your pointers will be size 8.

To change back to 32bit, open the configuration manager again and choose the correct Configuration and Platform.

Upvotes: 0

david.pfx
david.pfx

Reputation: 10868

The Intel CPUs have the ability to execute 16, 32 and 64-bit binaries. The question is: which were you testing?

Both Windows and Linux are available in 32 and 64-bit versions. The difference is that 32-bit cannot execute 64-bit binaries, whereas 64-bit can.

If (and only if) you have a 64-bit OS and a 64-bit-capable development system and you write a program and explicitly tell it to generate a 64-bit program then when you run it you will see 8 byte pointers.

Upvotes: 2

Related Questions