Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have the following program that prints 4. I am running this program on Windows 7 64-bit. Shouldn't it print 8 for 64-bit platform? Thanks in advance.

#include <stdio.h>
void main()
{
    printf("%d", sizeof(void*));
}
like image 337
user2340048 Avatar asked May 29 '13 21:05

user2340048


1 Answers

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

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

In Visual Studio 2010, to to the properties page of your C/C++ project, and make sure that Active (x64) is selected in the "Platform" drop-down (it's Win32 by default). If x64 is not available in the dropdown, click [Configuration Manager...], and choose x64 for the platform of your project. If a "Copy from..." dialog opens, click [OK] to dismiss it. The program should run in 64-bit mode after a recompile.

like image 57
Sergey Kalinichenko Avatar answered Oct 15 '22 22:10

Sergey Kalinichenko