Issue
I am beginner regarding gcc command line compilation. I need a help regarding -m64 flag.
I installed gcc compiler using MinGW.
I checked for gcc version by following,
gcc -v
command, which shows Target: x86_64-w64-mingw32
.
So I assume, 64-bit version of gcc is installed.
Objective: I wrote a small program to check, if the main.exe is generated for 32 or 64 bit.
#include<stdio.h>
int main(void)
{
printf("The Size is: %lu\n", sizeof(long));
return 0;
}
I compiled using following command, gcc -o main main.c
. When I execute the main.exe, it outputs, The Size is: 4
.
But I expected the output to be `The Size is: 8'.
So i modified the command as gcc -m64 -o main main.c
. When I executed the main.exe again, still it outputs `The Size is: 4'
How to compile for 64-bit version exe?
Solution
As others have said in the comments, the size of long
can be 8 or 4 bytes on a 64bit system. You can try sizeof(size_t)
or sizeof(void*)
. Even this might not be reliable on every system (but should work for Windows, Linux, macOS).
Answered By - Christian Halaszovich