I have downloaded MinGW-64, so I can now compile 64-bit programs for Windows 7, using g++ 4.7.0 (experimental). But the following line:
cout << sizeof(long) << " " << sizeof(void*) << endl ;
prints 4 8
, not 8 8
. The documentation for g++ 4.6.0 says:
The 64-bit environment sets int to 32 bits and long and pointer to 64 bits
Does anybody know why sizeof(long)
is not 8?
Edited to add: The source of my confusion was that g++ 4.7.0 for 64-bit Windows is not (yet) an official part of the GNU Compiler Collection. And it's the first 64-bit version with a 32-bit long
, so the documentation simply doesn't apply to it. Indeed, if you go to the relevant web page, the full entry for IA-32/x86-64 consists of this:
...
Windows: long and int remain 32-bit in length, and special new data types are defined for 64-bit integers.
int , long , ptr , and off_t are all 32 bits (4 bytes) in size. int is 32 bits in size. long , ptr , and off_t are all 64 bits (8 bytes) in size.
LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit)
unsigned long. 8 bytes. 0 to 18446744073709551615. To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes.
Because it doesn't have to be. The C++ standard only requires that it is (if memory serves) at least 32 bits wide, and at least as big as int
.
MSVC (and the ABI used by Windows) defines long
to be 32 bits wide, and MingW follows suit because well, the compiler is a lot more useful when it agrees with the host OS
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