I'm using the MinGW-w64 version tagged as x86_64-8.1.0-posix-seh-rt_v6-rev0
. When running g++ --version
, I see this:
g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
From my understanding, this version of g++ should generate 64-bit binaries by default.
The compiler command is like this:
g++.exe -std=c++17 -g main.cpp -o main.exe
However, if main.cpp
looks like this:
#include <iostream>
int main() {
std::cout << sizeof(long);
return 0;
}
It prints 4
instead of 8
. I tried using a -m64
compiler flag, but it changed nothing.
What am I doing wrong, and how to fix this?
long
is not guaranteed to be 64 bits in size in a 64bit executable. In fact, on Windows, long
is always 32 bits under both x86 and x64. Use long long
or __int64
or int64_t
if you need a 64 bit integer. If you just want to check if your executable is compiled for 32-bit vs 64-bit, use sizeof(void*)
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With