Why the void pointer size is 4 on a 64-bit Windows platform

I have the following program that prints 4. I am running this program on a 64-bit version of Windows 7. Should it print 8 for a 64-bit platform? Thanks in advance.

#include <stdio.h> void main() { printf("%d", sizeof(void*)); } 
+6
source share
1 answer

When you use a compiled language such as C, the size of the pointer is not determined by the platform on which you use your code: it depends only on the platform on which you compiled your code.

The 64-bit version of Windows 7 can run code compiled for 32-bit platforms. Judging by the conclusions of your program, it seems that your code has been compiled for Win-32.

In Visual Studio 2010 go to the properties page of your C / C ++ project and make sure that Active (x64) selected in the "Platform" drop-down list (by default it is Win32). If x64 not available in the drop-down list, click [Configuration Manager...] and select x64 for your project platform. If the "Copy from ..." dialog box [OK] , click [OK] to reject it. After recompilation, the program should work in 64-bit mode.

+11
source

Source: https://habr.com/ru/post/946125/


All Articles